Commit 01378ab4 authored by James Lopez's avatar James Lopez

update profiles controller to use new service

parent 59c3968c
......@@ -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
......
......@@ -10,17 +10,17 @@ module Users
def execute(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block)
if @user.save
if @user.save || !@user.changed?
success
else
error('User could not be updated')
error("User could not be updated #{@user.errors.full_messages.uniq.join('. ')}" )
end
end
def execute!(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block)
@user.save!
@user.save! if @user.changed?
end
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