Skip to content

Commit

Permalink
Redirect to profile page if user not logged in when login required
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Apr 30, 2024
1 parent dd55c39 commit 3e4039e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def set_default_event
request.path_parameters[:event_name] = @event.name
end

def make_sure_user_has_profile
return if @user&.profile

session[:breakout_turbo] = true
redirect_to profile_path, flash: { error: I18n.t('errors.login_required') }
end

def create_and_set_user
@user = User.create!
session[:user_id] = @user.id
Expand Down
1 change: 1 addition & 0 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class MembersController < ApplicationController
class NoPermissionError < StandardError; end

before_action :make_sure_user_logged_in
before_action :set_team
before_action :set_team_profile, except: :create
before_action :define_error_variable
Expand Down
1 change: 1 addition & 0 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class TeamsController < ApplicationController
class InvalidStateError < StandardError; end

before_action :make_sure_user_logged_in
before_action :set_team, only: %i[show edit update destroy]
before_action :check_user_belongs_to_team, only: %i[show update destroy]

Expand Down
10 changes: 1 addition & 9 deletions app/controllers/triggers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@

class TriggersController < ApplicationController
prepend_before_action :set_default_event
before_action :make_sure_user_has_profile
before_action :make_sure_user_logged_in

def show
trigger = Trigger.find(params[:id])
trigger.perform(@user.profile, params[:key])

redirect_to profile_path
end

private

def make_sure_user_has_profile
return if @user&.profile

redirect_to profile_path, flash: { error: I18n.t('errors.login_required') }
end
end

0 comments on commit 3e4039e

Please sign in to comment.