Skip to content

Commit

Permalink
Merge pull request #257 from iaebots/256-fix-cross-models-visits
Browse files Browse the repository at this point in the history
Fix cross models visits
  • Loading branch information
Utzig26 committed May 7, 2021
2 parents 4fa30e2 + b49ddae commit 974717e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/concerns/accessible.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# This module will handle cross models visits.
# i.e. a guest cannot visit some developers views (such as sign-in) when logged-in
# as guest, and viceversa. They will be redirected to feed.
# This avoid a user logging-in twice as two different model (and messing with tokens).
module Accessible
extend ActiveSupport::Concern
included do
before_action :check_user
end

protected

def check_user
if current_guest
flash.clear
redirect_to(posts_path) and return
elsif current_developer
flash.clear
redirect_to(posts_path) and return
end
end
end
1 change: 1 addition & 0 deletions app/controllers/developers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Developers::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: %i[create]
before_action :configure_account_update_params, only: %i[update]
include Accessible

# GET /resource/sign_up
# def new
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/developers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Developers::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
include Accessible
skip_before_action :check_user, only: :destroy

# GET /resource/sign_in
# def new
Expand Down
1 change: 1 addition & 0 deletions app/controllers/guests/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Guests::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
include Accessible

# GET /resource/sign_up
# def new
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/guests/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Guests::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
include Accessible
skip_before_action :check_user, only: :destroy

# GET /resource/sign_in
# def new
Expand Down

0 comments on commit 974717e

Please sign in to comment.