2013-01-07 09:04:09 +01:00
|
|
|
class RegistrationsController < Devise::RegistrationsController
|
2014-05-16 20:31:41 +02:00
|
|
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
|
|
|
|
|
2014-06-18 16:58:30 +03:00
|
|
|
def edit
|
|
|
|
|
@openids = Openid.where(user_id: current_user.id).order(:provider)
|
|
|
|
|
end
|
|
|
|
|
|
2013-01-07 09:04:09 +01:00
|
|
|
def update
|
2014-06-26 15:43:24 +03:00
|
|
|
@openids = Openid.where(user_id: current_user.id).order(:provider)
|
2013-01-07 09:04:09 +01:00
|
|
|
@user = User.find(current_user.id)
|
|
|
|
|
email_changed = false
|
|
|
|
|
|
|
|
|
|
if !params[:user][:email].nil?
|
|
|
|
|
if @user.email != params[:user][:email]
|
|
|
|
|
email_changed = true
|
|
|
|
|
else
|
|
|
|
|
params[:user].delete :email
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
password_changed = false
|
|
|
|
|
if !params[:user][:password].nil?
|
|
|
|
|
if !params[:user][:password].empty?
|
2014-06-26 15:43:24 +03:00
|
|
|
password_changed = true
|
2013-01-07 09:04:09 +01:00
|
|
|
else
|
|
|
|
|
params[:user].delete :password
|
|
|
|
|
params[:user].delete :password_confirmation
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-26 15:43:24 +03:00
|
|
|
if email_changed || password_changed
|
2014-05-16 20:31:41 +02:00
|
|
|
successfully_updated = @user.update_with_password(account_update_params)
|
2013-02-02 16:43:47 +01:00
|
|
|
else
|
2013-02-06 07:23:35 +01:00
|
|
|
params[:user].delete :current_password
|
2014-05-16 20:31:41 +02:00
|
|
|
successfully_updated = @user.update_without_password(account_update_params)
|
2013-02-02 16:43:47 +01:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
|
|
|
|
if successfully_updated
|
2013-02-06 07:23:35 +01:00
|
|
|
if email_changed
|
2014-06-26 15:43:24 +03:00
|
|
|
unless @user.nil?
|
2014-06-23 19:07:50 +03:00
|
|
|
@user.update_attribute('email', params[:user][:email])
|
2013-02-06 07:23:35 +01:00
|
|
|
end
|
|
|
|
|
set_flash_message :notice, :update_needs_confirmation
|
|
|
|
|
else
|
|
|
|
|
set_flash_message :notice, :updated
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
# Sign in the user bypassing validation in case his password changed
|
2014-06-23 19:07:50 +03:00
|
|
|
sign_in @user, bypass: true
|
2013-01-07 09:04:09 +01:00
|
|
|
redirect_to after_update_path_for(@user)
|
|
|
|
|
else
|
2014-05-16 20:31:41 +02:00
|
|
|
flash[:alert] = 'Updating account failed. ' \
|
|
|
|
|
"#{@user.errors.full_messages.join('. ')}."
|
|
|
|
|
render 'edit'
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def after_update_path_for(resource)
|
|
|
|
|
edit_user_registration_path(resource)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def after_sign_up_path_for(resource)
|
|
|
|
|
edit_user_registration_path(resource)
|
|
|
|
|
end
|
|
|
|
|
|
2014-05-16 20:31:41 +02:00
|
|
|
def configure_permitted_parameters
|
|
|
|
|
devise_parameter_sanitizer.for(:account_update) do |u|
|
|
|
|
|
u.
|
2014-06-26 15:43:24 +03:00
|
|
|
permit(:email, :password, :password_confirmation, :current_password, :name, :biography,
|
2014-11-03 15:25:33 +01:00
|
|
|
:nickname, :affiliation, :username)
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
|
|
|
|
devise_parameter_sanitizer.for(:sign_up) do |u|
|
|
|
|
|
u.
|
2014-11-03 15:25:33 +01:00
|
|
|
permit(:email, :password, :password_confirmation, :name, :username)
|
2014-05-16 20:31:41 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|