2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-23 10:02:01 +02:00
|
|
|
class Users::PasswordsController < Devise::PasswordsController
|
2021-09-02 21:20:30 +02:00
|
|
|
include DevisePopulatedResource
|
|
|
|
|
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
|
2021-09-02 21:20:30 +02:00
|
|
|
# def create
|
|
|
|
# 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
|
|
|
|
|
2021-04-22 12:07:35 +02:00
|
|
|
def reset_link_sent
|
2024-02-27 18:46:06 +01:00
|
|
|
@email = message_verifier.verify(params[:email], purpose: :reset_password) rescue nil
|
2021-04-22 12:07:35 +02:00
|
|
|
end
|
|
|
|
|
2021-08-26 22:04:13 +02:00
|
|
|
protected
|
2015-09-23 10:02:01 +02:00
|
|
|
|
|
|
|
# def after_resetting_password_path_for(resource)
|
|
|
|
# super(resource)
|
|
|
|
# end
|
|
|
|
|
2021-08-26 22:04:13 +02:00
|
|
|
def after_sending_reset_password_instructions_path_for(resource_name)
|
|
|
|
flash.discard(:notice)
|
2024-02-27 18:46:06 +01:00
|
|
|
signed_email = message_verifier.generate(resource.email, purpose: :reset_password, expires_in: 1.hour)
|
|
|
|
users_password_reset_link_sent_path(email: signed_email)
|
2021-08-26 22:04:13 +02:00
|
|
|
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-10-15 17:44:59 +02:00
|
|
|
instructeur = Instructeur.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?
|
2020-01-30 17:08:09 +01:00
|
|
|
administrateur = Administrateur.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
|
2015-09-23 10:02:01 +02:00
|
|
|
end
|