Class: QuoVadis::PasswordResetsController
- Inherits:
-
QuoVadisController
- Object
- ApplicationController
- QuoVadisController
- QuoVadis::PasswordResetsController
- Defined in:
- app/controllers/quo_vadis/password_resets_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
generate and email an otp.
-
#edit ⇒ Object
form for otp and new password.
-
#new ⇒ Object
form where user enters their identifier.
-
#update ⇒ Object
update password if otp and password are valid.
Instance Method Details
#create ⇒ Object
generate and email an otp
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/quo_vadis/password_resets_controller.rb', line 12 def create account = QuoVadis.find_account_by_identifier_in_params params # The recommendation is to show the user the same message whether # or not their account was found. This favours privacy over # helpfulness and is the default. # # If you would prefer helpfulness over privacy -- perhaps the user # simply typo'd their identifier -- set the `unknown` flash message # to something helpful. = QuoVadis.translate('flash.password_reset.create') = QuoVadis.translate('flash.password_reset.unknown') if == flash[:notice] = elsif account flash[:notice] = else flash[:alert] = end if account session[:account_resetting_password] = account.id expiration = QuoVadis.password_reset_otp_lifetime.from_now.to_i session[:password_reset_expires_at] = expiration otp = account.otp_for_password_reset(expiration) QuoVadis.deliver :reset_password, {email: account.model.email, otp: otp} end redirect_to edit_password_reset_path end |
#edit ⇒ Object
form for otp and new password
49 50 51 |
# File 'app/controllers/quo_vadis/password_resets_controller.rb', line 49 def edit @password = QuoVadis::Password.new end |
#new ⇒ Object
form where user enters their identifier
7 8 |
# File 'app/controllers/quo_vadis/password_resets_controller.rb', line 7 def new end |
#update ⇒ Object
update password if otp and password are valid
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/quo_vadis/password_resets_controller.rb', line 55 def update account = find_account_resetting_password_from_session unless account redirect_to new_password_reset_path return end expiry = session[:password_reset_expires_at] if Time.current.to_i > expiry redirect_to new_password_reset_path, alert: QuoVadis.translate('flash.password_reset.expired') return end unless account.verify_password_reset(params[:password][:otp], expiry) redirect_to new_password_reset_path, alert: QuoVadis.translate('flash.password_reset.invalid') return end @password = account.password unless @password.reset(params[:password][:password], params[:password][:password_confirmation]) render :edit, status: :unprocessable_entity return end session.delete :account_resetting_password session.delete :password_reset_expires_at qv.log account, Log::PASSWORD_RESET QuoVadis.notify :password_reset_notification, email: account.model.email login account.model, true redirect_to qv.path_after_authentication, notice: QuoVadis.translate('flash.password_reset.reset') end |