emails: move edit email flow to emails controller.
This commit is contained in:
36
app/controllers/emails_controller.rb
Normal file
36
app/controllers/emails_controller.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class EmailsController < ApplicationController
|
||||
before_action :member_only
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:user_id])
|
||||
check_privilege(@user)
|
||||
|
||||
respond_with(@user)
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:user_id])
|
||||
check_privilege(@user)
|
||||
|
||||
if User.authenticate(@user.name, params[:user][:password])
|
||||
@user.update(email_address_attributes: { address: params[:user][:email] })
|
||||
else
|
||||
@user.errors[:base] << "Password was incorrect"
|
||||
end
|
||||
|
||||
if @user.errors.none?
|
||||
flash[:notice] = "Email updated"
|
||||
respond_with(@user, location: settings_url)
|
||||
else
|
||||
flash[:notice] = @user.errors.full_messages.join("; ")
|
||||
respond_with(@user)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_privilege(user)
|
||||
raise User::PrivilegeError unless user.id == CurrentUser.id || CurrentUser.is_admin?
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class EmailChangesController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
email_change = UserEmailChange.new(CurrentUser.user, params[:email_change][:email], params[:email_change][:password])
|
||||
email_change.process
|
||||
if CurrentUser.user.errors.any?
|
||||
flash[:notice] = CurrentUser.user.errors.full_messages.join("; ")
|
||||
redirect_to(new_maintenance_user_email_change_path)
|
||||
else
|
||||
redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user