add alert for account is locked

This commit is contained in:
pedong 2019-06-25 18:00:13 +02:00 committed by Pierre de La Morinerie
parent 0ed9c4cbd4
commit 9438f962c5
2 changed files with 18 additions and 10 deletions

View file

@ -15,9 +15,14 @@ class Users::SessionsController < Sessions::SessionsController
# POST /resource/sign_in # POST /resource/sign_in
def create def create
remember_me = params[:user][:remember_me] == '1' remember_me = params[:user][:remember_me] == '1'
try_to_authenticate(User, remember_me)
try_to_authenticate(Gestionnaire, remember_me) if resource_locked?(try_to_authenticate(User, remember_me)) ||
try_to_authenticate(Administrateur, remember_me) resource_locked?(try_to_authenticate(Gestionnaire, remember_me)) ||
resource_locked?(try_to_authenticate(Administrateur, remember_me))
flash.alert = 'Votre compte est verrouillé.'
new
return render :new, status: 401
end
if user_signed_in? if user_signed_in?
current_user.update(loged_in_with_france_connect: nil) current_user.update(loged_in_with_france_connect: nil)
@ -103,13 +108,16 @@ class Users::SessionsController < Sessions::SessionsController
resource = klass.find_for_database_authentication(email: params[:user][:email]) resource = klass.find_for_database_authentication(email: params[:user][:email])
if resource.present? if resource.present?
if resource.access_locked? if resource.valid_password?(params[:user][:password])
if resource.valid_password?(params[:user][:password]) resource.remember_me = remember_me
resource.remember_me = remember_me sign_in resource
sign_in resource resource.force_sync_credentials
resource.force_sync_credentials
end
end end
end end
resource
end
def resource_locked?(resource)
resource.present? && resource.access_locked?
end end
end end

View file

@ -164,7 +164,7 @@ Devise.setup do |config|
config.lock_strategy = :failed_attempts config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account # Defines which key will be used when locking and unlocking an account
config.unlock_keys = [ :email ] config.unlock_keys = [:email]
# Defines which strategy will be used to unlock an account. # Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email # :email = Sends an unlock link to the user email