mailers: add procedure context to the confirmation link
This allows to redirect the user to the procedure they signed up for even when the browser session is not available (like if they changed of browser). Fix #4738
This commit is contained in:
parent
10c940c188
commit
6664965961
8 changed files with 50 additions and 5 deletions
|
@ -42,9 +42,19 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
|
|||
if sign_in_after_confirmation?(resource)
|
||||
resource.remember_me = true
|
||||
sign_in(resource)
|
||||
end
|
||||
|
||||
if procedure_from_params
|
||||
commencer_path(path: procedure_from_params.path)
|
||||
elsif signed_in?
|
||||
# Will try to use `stored_location_for` to find a path
|
||||
after_sign_in_path_for(resource_name)
|
||||
else
|
||||
super(resource_name, resource)
|
||||
end
|
||||
end
|
||||
|
||||
def procedure_from_params
|
||||
params[:procedure_id] && Procedure.find_by(id: params[:procedure_id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,12 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
|||
|
||||
# POST /resource
|
||||
def create
|
||||
# We may need the confirmation mailer to access the current procedure.
|
||||
# But there's no easy way to pass an argument to the mailer through
|
||||
# all Devise code.
|
||||
# So instead we use a per-request global variable.
|
||||
CurrentConfirmation.procedure_after_confirmation = @procedure
|
||||
|
||||
# Handle existing user trying to sign up again
|
||||
existing_user = User.find_by(email: params[:user][:email])
|
||||
if existing_user.present?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue