diff options
author | James Lopez <james@jameslopez.es> | 2017-06-14 12:39:58 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-06-23 11:41:41 +0200 |
commit | 01378ab4a57dfbca589efdffb6d13e1830913106 (patch) | |
tree | 4723e360808c405648a0b8f89a2a600166097a13 /app/controllers/profiles_controller.rb | |
parent | 59c3968c40a1146f5370ae3b634aac2d4a045733 (diff) | |
download | gitlab-ce-01378ab4a57dfbca589efdffb6d13e1830913106.tar.gz |
update profiles controller to use new service
Diffstat (limited to 'app/controllers/profiles_controller.rb')
-rw-r--r-- | app/controllers/profiles_controller.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index f98a9e24de1..09161daa7ed 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -12,39 +12,47 @@ class ProfilesController < Profiles::ApplicationController user_params.except!(:email) if @user.external_email? respond_to do |format| - if @user.update_attributes(user_params) + status = Users::UpdateService.new(current_user, @user, user_params).execute + + if status[:success] message = "Profile was successfully updated" + format.html { redirect_back_or_default(default: { action: 'show' }, options: { notice: message }) } format.json { render json: { message: message } } else - message = @user.errors.full_messages.uniq.join('. ') - format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: "Failed to update profile. #{message}" }) } - format.json { render json: { message: message }, status: :unprocessable_entity } + format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: status[:message] }) } + format.json { render json: status } end end end def reset_private_token - if current_user.reset_authentication_token! - flash[:notice] = "Private token was successfully reset" + Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user| + user.reset_authentication_token! end + flash[:notice] = "Private token was successfully reset" + redirect_to profile_account_path end def reset_incoming_email_token - if current_user.reset_incoming_email_token! - flash[:notice] = "Incoming email token was successfully reset" + Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user| + user.reset_incoming_email_token! end + flash[:notice] = "Incoming email token was successfully reset" + redirect_to profile_account_path end def reset_rss_token - if current_user.reset_rss_token! - flash[:notice] = "RSS token was successfully reset" + Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user| + user.reset_rss_token! end + flash[:notice] = "RSS token was successfully reset" + redirect_to profile_account_path end |