2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-03 07:38:22 -07:00
|
|
|
class Auth::ConfirmationsController < Devise::ConfirmationsController
|
2023-11-30 06:39:41 -08:00
|
|
|
include Auth::CaptchaConcern
|
2023-05-16 14:27:35 -07:00
|
|
|
|
2016-10-03 07:38:22 -07:00
|
|
|
layout 'auth'
|
2018-02-03 20:42:13 -08:00
|
|
|
|
2018-07-30 16:14:33 -07:00
|
|
|
before_action :set_body_classes
|
2023-05-16 14:27:35 -07:00
|
|
|
before_action :set_confirmation_user!, only: [:show, :confirm_captcha]
|
2024-01-25 07:13:41 -08:00
|
|
|
before_action :redirect_confirmed_user, if: :signed_in_confirmed_user?
|
2018-02-03 20:42:13 -08:00
|
|
|
|
2023-05-16 14:27:35 -07:00
|
|
|
before_action :extend_csp_for_captcha!, only: [:show, :confirm_captcha]
|
|
|
|
before_action :require_captcha_if_needed!, only: [:show]
|
|
|
|
|
2023-10-23 08:46:21 -07:00
|
|
|
skip_before_action :check_self_destruct!
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 01:48:50 -07:00
|
|
|
skip_before_action :require_functional!
|
2018-02-03 20:42:13 -08:00
|
|
|
|
2023-05-16 14:27:35 -07:00
|
|
|
def show
|
|
|
|
old_session_values = session.to_hash
|
|
|
|
reset_session
|
|
|
|
session.update old_session_values.except('session_id')
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2019-09-03 19:13:54 -07:00
|
|
|
def new
|
|
|
|
super
|
|
|
|
|
|
|
|
resource.email = current_user.unconfirmed_email || current_user.email if user_signed_in?
|
|
|
|
end
|
|
|
|
|
2023-05-16 14:27:35 -07:00
|
|
|
def confirm_captcha
|
|
|
|
check_captcha! do |message|
|
|
|
|
flash.now[:alert] = message
|
|
|
|
render :captcha
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
show
|
|
|
|
end
|
|
|
|
|
2023-10-25 14:33:44 -07:00
|
|
|
def redirect_to_app?
|
|
|
|
truthy_param?(:redirect_to_app)
|
|
|
|
end
|
|
|
|
|
|
|
|
helper_method :redirect_to_app?
|
|
|
|
|
2018-02-03 20:42:13 -08:00
|
|
|
private
|
|
|
|
|
2023-05-16 14:27:35 -07:00
|
|
|
def require_captcha_if_needed!
|
|
|
|
render :captcha if captcha_required?
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_confirmation_user!
|
|
|
|
# We need to reimplement looking up the user because
|
|
|
|
# Devise::ConfirmationsController#show looks up and confirms in one
|
|
|
|
# step.
|
|
|
|
confirmation_token = params[:confirmation_token]
|
|
|
|
return if confirmation_token.nil?
|
|
|
|
|
|
|
|
@confirmation_user = User.find_first_by_auth_conditions(confirmation_token: confirmation_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def captcha_user_bypass?
|
2023-12-18 01:50:51 -08:00
|
|
|
@confirmation_user.nil? || @confirmation_user.confirmed?
|
2023-05-16 14:27:35 -07:00
|
|
|
end
|
|
|
|
|
2024-01-25 07:13:41 -08:00
|
|
|
def redirect_confirmed_user
|
|
|
|
redirect_to(current_user.approved? ? root_path : edit_user_registration_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def signed_in_confirmed_user?
|
|
|
|
user_signed_in? && current_user.confirmed? && current_user.unconfirmed_email.blank?
|
2019-09-03 19:13:54 -07:00
|
|
|
end
|
|
|
|
|
2018-07-30 16:14:33 -07:00
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'lighter'
|
|
|
|
end
|
|
|
|
|
2019-09-03 19:13:54 -07:00
|
|
|
def after_resending_confirmation_instructions_path_for(_resource_name)
|
|
|
|
if user_signed_in?
|
2019-09-04 21:13:50 -07:00
|
|
|
if current_user.confirmed? && current_user.approved?
|
2019-09-03 19:13:54 -07:00
|
|
|
edit_user_registration_path
|
|
|
|
else
|
|
|
|
auth_setup_path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
new_user_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-24 10:12:38 -08:00
|
|
|
def after_confirmation_path_for(_resource_name, user)
|
2023-10-25 14:33:44 -07:00
|
|
|
if user.created_by_application && redirect_to_app?
|
2022-05-26 13:03:54 -07:00
|
|
|
user.created_by_application.confirmation_redirect_uri
|
2023-06-14 00:05:03 -07:00
|
|
|
elsif user_signed_in?
|
|
|
|
web_url('start')
|
2018-12-24 10:12:38 -08:00
|
|
|
else
|
2023-06-14 00:05:03 -07:00
|
|
|
new_user_session_path
|
2018-12-24 10:12:38 -08:00
|
|
|
end
|
|
|
|
end
|
2016-10-03 07:38:22 -07:00
|
|
|
end
|