Module: ActiveAuthentication::Model::Lockable

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_authentication/model/lockable.rb

Instance Method Summary collapse

Instance Method Details

#increment_failed_attemptsObject



14
15
16
17
18
19
20
# File 'lib/active_authentication/model/lockable.rb', line 14

def increment_failed_attempts
  increment :failed_attempts

  lock if failed_attempts == ActiveAuthentication.max_failed_attempts

  save
end

#lockObject



26
27
28
29
30
# File 'lib/active_authentication/model/lockable.rb', line 26

def lock
  update locked_at: Time.now

  send_unlock_instructions
end

#locked?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/active_authentication/model/lockable.rb', line 22

def locked?
  locked_at.present?
end

#send_unlock_instructionsObject



32
33
34
35
# File 'lib/active_authentication/model/lockable.rb', line 32

def send_unlock_instructions
  token = generate_token_for :unlock
  ActiveAuthentication::Mailer.with(token: token, user: self).unlock_instructions.deliver
end

#unlockObject



37
38
39
# File 'lib/active_authentication/model/lockable.rb', line 37

def unlock
  update failed_attempts: 0, locked_at: nil
end