Session: send a mail to confirm gestionnaire login

This commit is contained in:
simon lehericey 2018-10-03 11:11:02 +02:00
parent 2613d05a4f
commit 5690599289
14 changed files with 215 additions and 30 deletions

View file

@ -1,6 +1,7 @@
class Gestionnaire < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
include ActiveRecord::SecureToken
devise :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable
@ -144,6 +145,20 @@ class Gestionnaire < ApplicationRecord
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
end
def login_token!
login_token = Gestionnaire.generate_unique_secure_token
encrypted_login_token = BCrypt::Password.create(login_token)
update(encrypted_login_token: encrypted_login_token, login_token_created_at: Time.zone.now)
login_token
end
def login_token_valid?(login_token)
BCrypt::Password.new(encrypted_login_token) == login_token
30.minutes.ago < login_token_created_at
rescue BCrypt::Errors::InvalidHash
false
end
def dossiers_id_with_notifications(dossiers)
dossiers = dossiers.followed_by(self)