2019-06-20 00:36:50 +02:00
|
|
|
class Administrateurs::PasswordsController < Devise::PasswordsController
|
|
|
|
after_action :try_to_authenticate_user, only: [:update]
|
2019-08-06 11:02:54 +02:00
|
|
|
after_action :try_to_authenticate_instructeur, only: [:update]
|
2019-06-20 00:36:50 +02:00
|
|
|
|
|
|
|
# GET /resource/password/new
|
|
|
|
# def new
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# POST /resource/password
|
|
|
|
# def create
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# GET /resource/password/edit?reset_password_token=abcdef
|
|
|
|
# def edit
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# PUT /resource/password
|
|
|
|
# def update
|
|
|
|
# # params[:user][:password_confirmation] = params[:user][:password]
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# protected
|
|
|
|
|
|
|
|
# def after_resetting_password_path_for(resource)
|
|
|
|
# super(resource)
|
|
|
|
# end
|
|
|
|
|
|
|
|
# The path used after sending reset password instructions
|
|
|
|
# def after_sending_reset_password_instructions_path_for(resource_name)
|
|
|
|
# super(resource_name)
|
|
|
|
# end
|
|
|
|
|
|
|
|
def try_to_authenticate_user
|
|
|
|
if administrateur_signed_in?
|
|
|
|
user = User.find_by(email: current_administrateur.email)
|
|
|
|
|
|
|
|
if user
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
def try_to_authenticate_instructeur
|
2019-06-20 00:36:50 +02:00
|
|
|
if administrateur_signed_in?
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur = Instructeur.find_by(email: current_administrateur.email)
|
2019-06-20 00:36:50 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
if instructeur
|
|
|
|
sign_in instructeur
|
2019-06-20 00:36:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_strength
|
|
|
|
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
|
|
|
|
@min_length = PASSWORD_MIN_LENGTH
|
|
|
|
@min_complexity = PASSWORD_COMPLEXITY_FOR_ADMIN
|
|
|
|
render 'shared/password/test_strength'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def password_params
|
|
|
|
params.require(:administrateur).permit(:reset_password_token, :password)
|
|
|
|
end
|
|
|
|
end
|