Module: Tyrant::Authenticatable::Confirm

Included in:
Tyrant::Authenticatable
Defined in:
lib/tyrant/authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#confirmable!Object



18
19
20
21
22
# File 'lib/tyrant/authenticatable.rb', line 18

def confirmable!
  .confirmation_token = "asdfasdfasfasfasdfasdf"
  .confirmation_created_at = DateTime.now
  self
end

#confirmable?(token = false) ⇒ Boolean

without token, this decides whether the user model can be activated (e.g. via “set a password”). with token, this additionally tests if the token is correct.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/tyrant/authenticatable.rb', line 26

def confirmable?(token=false)
  persisted_token = .confirmation_token

  # TODO: add expiry etc.
  return false unless (persisted_token.is_a?(String) and persisted_token.size > 0)

  return compare_token(token) unless token==false
  true
end

#confirmation_tokenObject



46
47
48
# File 'lib/tyrant/authenticatable.rb', line 46

def confirmation_token
  .confirmation_token
end

#confirmed!(confirmed_at = DateTime.now) ⇒ Object



41
42
43
44
# File 'lib/tyrant/authenticatable.rb', line 41

def confirmed!(confirmed_at=DateTime.now)
  .confirmation_token = nil
  .confirmed_at       = confirmed_at # TODO: test optional arg.
end

#confirmed?Boolean

alias_method :confirmed?, :confirmable?

Returns:

  • (Boolean)


37
38
39
# File 'lib/tyrant/authenticatable.rb', line 37

def confirmed?
  not .confirmed_at.nil?
end