-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccounts_controller.rb
More file actions
36 lines (29 loc) · 1.02 KB
/
accounts_controller.rb
File metadata and controls
36 lines (29 loc) · 1.02 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
class Users::AccountsController < ApplicationController
before_action :authenticate_user!
skip_after_action :verify_authorized
def edit
@email_form = Users::UpdateEmailForm.new({ email: current_user.email })
@password_form = Users::ForgotPasswordForm.new({ email: current_user.email })
end
def update_email
@email_form = Users::UpdateEmailForm.new(user_email_params)
if @email_form.invalid?
flash.now[:errors] = @email_form.errors.full_messages
return render :edit, status: :unprocessable_entity
end
begin
auth_service.change_email(current_user.uid, @email_form.email)
rescue Auth::Errors::BaseAuthError => e
flash.now[:errors] = [ e.message ]
return render :edit, status: :unprocessable_entity
end
redirect_to({ action: :edit }, notice: "Account updated successfully.")
end
private
def auth_service
AuthServiceFactory.instance.auth_service
end
def user_email_params
params.require(:users_update_email_form).permit(:email)
end
end