BigW Consortium Gitlab

Commit 01378ab4 by James Lopez

update profiles controller to use new service

parent 59c3968c
...@@ -12,39 +12,47 @@ class ProfilesController < Profiles::ApplicationController ...@@ -12,39 +12,47 @@ class ProfilesController < Profiles::ApplicationController
user_params.except!(:email) if @user.external_email? user_params.except!(:email) if @user.external_email?
respond_to do |format| 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" message = "Profile was successfully updated"
format.html { redirect_back_or_default(default: { action: 'show' }, options: { notice: message }) } format.html { redirect_back_or_default(default: { action: 'show' }, options: { notice: message }) }
format.json { render json: { message: message } } format.json { render json: { message: message } }
else else
message = @user.errors.full_messages.uniq.join('. ') format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: status[:message] }) }
format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: "Failed to update profile. #{message}" }) } format.json { render json: status }
format.json { render json: { message: message }, status: :unprocessable_entity }
end end
end end
end end
def reset_private_token def reset_private_token
if current_user.reset_authentication_token! Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user|
flash[:notice] = "Private token was successfully reset" user.reset_authentication_token!
end end
flash[:notice] = "Private token was successfully reset"
redirect_to profile_account_path redirect_to profile_account_path
end end
def reset_incoming_email_token def reset_incoming_email_token
if current_user.reset_incoming_email_token! Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user|
flash[:notice] = "Incoming email token was successfully reset" user.reset_incoming_email_token!
end end
flash[:notice] = "Incoming email token was successfully reset"
redirect_to profile_account_path redirect_to profile_account_path
end end
def reset_rss_token def reset_rss_token
if current_user.reset_rss_token! Users::UpdateService.new(current_user, @user).execute!(skip_authorization: true) do |user|
flash[:notice] = "RSS token was successfully reset" user.reset_rss_token!
end end
flash[:notice] = "RSS token was successfully reset"
redirect_to profile_account_path redirect_to profile_account_path
end end
......
...@@ -10,17 +10,17 @@ module Users ...@@ -10,17 +10,17 @@ module Users
def execute(skip_authorization: false, &block) def execute(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block) assign_attributes(skip_authorization, &block)
if @user.save if @user.save || !@user.changed?
success success
else else
error('User could not be updated') error("User could not be updated #{@user.errors.full_messages.uniq.join('. ')}" )
end end
end end
def execute!(skip_authorization: false, &block) def execute!(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block) assign_attributes(skip_authorization, &block)
@user.save! @user.save! if @user.changed?
end end
private private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment