Implements iChain authentication
This commit is contained in:
parent
15c6ed127f
commit
49d565def2
21 changed files with 269 additions and 126 deletions
|
|
@ -3,55 +3,12 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
|
||||
def edit
|
||||
@openids = Openid.where(user_id: current_user.id).order(:provider)
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
@openids = Openid.where(user_id: current_user.id).order(:provider)
|
||||
@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?
|
||||
password_changed = true
|
||||
else
|
||||
params[:user].delete :password
|
||||
params[:user].delete :password_confirmation
|
||||
end
|
||||
end
|
||||
|
||||
if email_changed || password_changed
|
||||
successfully_updated = @user.update_with_password(account_update_params)
|
||||
else
|
||||
params[:user].delete :current_password
|
||||
successfully_updated = @user.update_without_password(account_update_params)
|
||||
end
|
||||
|
||||
if successfully_updated
|
||||
if email_changed
|
||||
unless @user.nil?
|
||||
@user.update_attribute('email', params[:user][:email])
|
||||
end
|
||||
set_flash_message :notice, :update_needs_confirmation
|
||||
else
|
||||
set_flash_message :notice, :updated
|
||||
end
|
||||
# Sign in the user bypassing validation in case his password changed
|
||||
sign_in @user, bypass: true
|
||||
redirect_to after_update_path_for(@user)
|
||||
else
|
||||
flash[:alert] = 'Updating account failed. ' \
|
||||
"#{@user.errors.full_messages.join('. ')}."
|
||||
render 'edit'
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
@ -67,8 +24,7 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.for(:account_update) do |u|
|
||||
u.
|
||||
permit(:email, :password, :password_confirmation, :current_password, :name, :biography,
|
||||
:nickname, :affiliation, :username)
|
||||
permit(:email, :password, :password_confirmation, :current_password, :username)
|
||||
end
|
||||
devise_parameter_sanitizer.for(:sign_up) do |u|
|
||||
u.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue