2015-09-23 10:02:01 +02:00
|
|
|
class Users::PasswordsController < Devise::PasswordsController
|
2019-08-06 11:02:54 +02:00
|
|
|
after_action :try_to_authenticate_instructeur, only: [:update]
|
2018-10-01 14:26:45 +02:00
|
|
|
after_action :try_to_authenticate_administrateur, only: [:update]
|
2016-10-13 18:26:08 +02:00
|
|
|
|
2015-09-23 10:02:01 +02:00
|
|
|
# GET /resource/password/new
|
|
|
|
# def new
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# POST /resource/password
|
2019-06-20 00:34:08 +02:00
|
|
|
def create
|
|
|
|
# Check the credentials associated to the mail to generate a correct reset link
|
|
|
|
email = params[:user][:email]
|
|
|
|
if Administrateur.find_by(email: email)
|
|
|
|
@devise_mapping = Devise.mappings[:administrateur]
|
|
|
|
params[:administrateur] = params[:user]
|
2019-08-06 11:02:54 +02:00
|
|
|
# uncomment to check password complexity for Instructeur
|
|
|
|
# elsif Instructeur.find_by(email: email)
|
|
|
|
# @devise_mapping = Devise.mappings[:instructeur]
|
|
|
|
# params[:instructeur] = params[:user]
|
2019-06-20 00:34:08 +02:00
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
2015-09-23 10:02:01 +02:00
|
|
|
|
|
|
|
# GET /resource/password/edit?reset_password_token=abcdef
|
|
|
|
# def edit
|
|
|
|
# super
|
|
|
|
# end
|
|
|
|
|
|
|
|
# PUT /resource/password
|
|
|
|
# def update
|
2019-06-20 00:34:08 +02:00
|
|
|
# # params[:user][:password_confirmation] = params[:user][:password]
|
2015-09-23 10:02:01 +02:00
|
|
|
# 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
|
2016-10-13 18:26:08 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
def try_to_authenticate_instructeur
|
2016-10-13 18:26:08 +02:00
|
|
|
if user_signed_in?
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur = Instructeur.find_by(email: current_user.email)
|
2018-10-01 13:24:37 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
if instructeur
|
2019-08-07 11:15:16 +02:00
|
|
|
sign_in(instructeur.user)
|
2018-10-01 13:24:37 +02:00
|
|
|
end
|
2016-10-13 18:26:08 +02:00
|
|
|
end
|
|
|
|
end
|
2016-12-07 17:35:45 +01:00
|
|
|
|
|
|
|
def try_to_authenticate_administrateur
|
|
|
|
if user_signed_in?
|
|
|
|
administrateur = Administrateur.find_by(email: current_user.email)
|
2018-10-01 13:24:37 +02:00
|
|
|
|
|
|
|
if administrateur
|
2019-08-09 10:46:39 +02:00
|
|
|
sign_in(administrateur.user)
|
2018-10-01 13:24:37 +02:00
|
|
|
end
|
2016-12-07 17:35:45 +01:00
|
|
|
end
|
|
|
|
end
|
2019-06-20 00:34:08 +02:00
|
|
|
|
|
|
|
def test_strength
|
|
|
|
@score, @words, @length = ZxcvbnService.new(password_params[:password]).complexity
|
|
|
|
@min_length = PASSWORD_MIN_LENGTH
|
|
|
|
@min_complexity = PASSWORD_COMPLEXITY_FOR_USER
|
|
|
|
render 'shared/password/test_strength'
|
|
|
|
end
|
|
|
|
|
|
|
|
def password_params
|
|
|
|
params.require(:user).permit(:reset_password_token, :password)
|
|
|
|
end
|
2015-09-23 10:02:01 +02:00
|
|
|
end
|