[Rails] Site internet de la World Tartiflette Tour.
1
classPasswordsController<ApplicationController
2
allow_unauthenticated_access
3
before_action :set_user_by_token, only: %i[ edit update ]
4
5
defnew
6
end
7
8
defcreate
9
if user = User.find_by(email_address: params[:email_address])
10
PasswordsMailer.reset(user).deliver_later
11
end
12
13
redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
14
end
15
16
defedit
17
end
18
19
defupdate
20
if @user.update(params.permit(:password, :password_confirmation))
21
redirect_to new_session_path, notice: "Password has been reset."
22
else
23
redirect_to edit_password_path([:token]), alert: "Passwords did not match."
24
end
25
end
26
27
private
28
defset_user_by_token
29
@user = User.find_by_password_reset_token!(params[:token])
30
rescue ActiveSupport::MessageVerifier::InvalidSignature
31
redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
32
end
33
end
34