28 lines
949 B
Ruby
28 lines
949 B
Ruby
class ProfileController < ApplicationController
|
|
before_action :authenticate_user!
|
|
|
|
def edit
|
|
end
|
|
|
|
def update_email
|
|
if current_user.valid_password?(params["current_password"]) && current_user.update(email: params["email"])
|
|
flash[:notice] = I18n.translate("flashes.profile.update.success")
|
|
redirect_to profile_path
|
|
else
|
|
flash[:alert] = I18n.translate("flashes.profile.update.fail")
|
|
redirect_to profile_path
|
|
end
|
|
end
|
|
|
|
def update_password
|
|
if !params["password"].blank? && current_user.valid_password?(params["current_password"]) && params["password"] == params["password_confirmation"] && current_user.update(password: params["password"])
|
|
bypass_sign_in(current_user)
|
|
flash[:notice] = I18n.translate("flashes.profile.update.success")
|
|
redirect_to profile_path
|
|
else
|
|
flash[:alert] = I18n.translate("flashes.profile.update.fail")
|
|
redirect_to profile_path
|
|
end
|
|
end
|
|
end
|