2019-08-07 15:52:38 +02:00
class Users :: ActivateController < ApplicationController
include TrustedDeviceConcern
def new
@user = User . with_reset_password_token ( params [ :token ] )
if @user
# the user activates its account from an email
trust_device ( Time . zone . now )
else
flash . alert = " Le lien de validation du compte instructeur a expiré, #{ helpers . contact_link ( 'contactez-nous' , tags : 'lien expiré' ) } pour obtenir un nouveau lien. "
redirect_to root_path
end
end
def create
user = User . reset_password_by_token ( {
2019-08-11 19:22:03 +02:00
password : user_params [ :password ] ,
reset_password_token : user_params [ :reset_password_token ]
2019-08-07 15:52:38 +02:00
} )
2019-08-11 19:22:03 +02:00
if user . valid?
2019-08-07 15:52:38 +02:00
sign_in ( user , scope : :user )
2019-08-09 10:38:27 +02:00
2019-08-07 15:52:38 +02:00
flash . notice = " Mot de passe enregistré "
redirect_to instructeur_procedures_path
else
flash . alert = user . errors . full_messages
2019-08-11 19:22:03 +02:00
redirect_to users_activate_path ( token : user_params [ :reset_password_token ] )
2019-08-07 15:52:38 +02:00
end
end
private
2019-08-11 19:22:03 +02:00
def user_params
2019-08-07 15:52:38 +02:00
params . require ( :user ) . permit ( :reset_password_token , :password )
end
end