-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpasswords_controller.rb
More file actions
65 lines (51 loc) · 1.67 KB
/
passwords_controller.rb
File metadata and controls
65 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
class Users::PasswordsController < ApplicationController
skip_after_action :verify_authorized
def forgot
@form = Users::ForgotPasswordForm.new
end
def send_reset_password_instructions
email = params[:users_forgot_password_form][:email]
spam_trap = params[:users_forgot_password_form][:spam_trap]
@form = Users::ForgotPasswordForm.new(email: email, spam_trap: spam_trap)
if @form.invalid?
flash.now[:errors] = @form.errors.full_messages
return render :forgot, status: :unprocessable_entity
end
begin
auth_service.forgot_password(email)
rescue Auth::Errors::BaseAuthError => e
flash.now[:errors] = [ e.message ]
return render :forgot, status: :unprocessable_entity
end
redirect_to users_reset_password_path
end
def reset
@form = Users::ResetPasswordForm.new
end
def confirm_reset
@form = Users::ResetPasswordForm.new(reset_password_params)
if @form.invalid?
flash.now[:errors] = @form.errors.full_messages
return render :reset, status: :unprocessable_entity
end
begin
auth_service.confirm_forgot_password(
@form.email,
@form.code,
@form.password
)
rescue Auth::Errors::BaseAuthError => e
flash.now[:errors] = [ e.message ]
return render :reset, status: :unprocessable_entity
end
redirect_to new_user_session_path, notice: I18n.t("users.passwords.reset.success")
end
private
def auth_service
AuthServiceFactory.instance.auth_service
end
def reset_password_params
params.require(:users_reset_password_form).permit(:email, :code, :password, :spam_trap)
end
end