Class: QuoVadis::PasswordResetsController

Inherits:
QuoVadisController show all
Defined in:
app/controllers/quo_vadis/password_resets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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
   = QuoVadis. 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.
  message_known   = QuoVadis.translate('flash.password_reset.create')
  message_unknown = QuoVadis.translate('flash.password_reset.unknown')

  if message_known == message_unknown
    flash[:notice] = message_known
  elsif 
    flash[:notice] = message_known
  else
    flash[:alert] = message_unknown
  end

  if 
    session[:account_resetting_password] = .id

    expiration = QuoVadis.password_reset_otp_lifetime.from_now.to_i
    session[:password_reset_expires_at] = expiration

    otp = .otp_for_password_reset(expiration)

    QuoVadis.deliver :reset_password, {email: .model.email, otp: otp}
  end

  redirect_to edit_password_reset_path
end

#editObject

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

#newObject

form where user enters their identifier



7
8
# File 'app/controllers/quo_vadis/password_resets_controller.rb', line 7

def new
end

#updateObject

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
   = 

  unless 
    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 .verify_password_reset(params[:password][:otp], expiry)
    redirect_to new_password_reset_path, alert: QuoVadis.translate('flash.password_reset.invalid')
    return
  end

  @password = .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 , Log::PASSWORD_RESET
  QuoVadis.notify :password_reset_notification, email: .model.email

   .model, true

  redirect_to qv.path_after_authentication, notice: QuoVadis.translate('flash.password_reset.reset')
end