Implements devise strong parameters for registration
This commit is contained in:
parent
7a209e10a7
commit
04c00e4b0c
1 changed files with 18 additions and 4 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@user = User.find(current_user.id)
|
@user = User.find(current_user.id)
|
||||||
email_changed = false
|
email_changed = false
|
||||||
|
|
@ -22,10 +24,10 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
end
|
end
|
||||||
|
|
||||||
if email_changed or password_changed
|
if email_changed or password_changed
|
||||||
successfully_updated = @user.update_with_password(params[:user])
|
successfully_updated = @user.update_with_password(account_update_params)
|
||||||
else
|
else
|
||||||
params[:user].delete :current_password
|
params[:user].delete :current_password
|
||||||
successfully_updated = @user.update_without_password(params[:user])
|
successfully_updated = @user.update_without_password(account_update_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
if successfully_updated
|
if successfully_updated
|
||||||
|
|
@ -41,7 +43,9 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
sign_in @user, :bypass => true
|
sign_in @user, :bypass => true
|
||||||
redirect_to after_update_path_for(@user)
|
redirect_to after_update_path_for(@user)
|
||||||
else
|
else
|
||||||
render "edit"
|
flash[:alert] = 'Updating account failed. ' \
|
||||||
|
"#{@user.errors.full_messages.join('. ')}."
|
||||||
|
render 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -55,4 +59,14 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
edit_user_registration_path(resource)
|
edit_user_registration_path(resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
def configure_permitted_parameters
|
||||||
|
devise_parameter_sanitizer.for(:account_update) do |u|
|
||||||
|
u.
|
||||||
|
permit(:email, :password, :password_confirmation, :current_password,
|
||||||
|
person_attributes: [:id, :email, :first_name, :last_name,
|
||||||
|
:public_name, :biography, :company, :avatar,
|
||||||
|
:irc_nickname, :mobile, :tshirt, :languages,
|
||||||
|
:volunteer_experience])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue