Module: Clearance::User::InstanceMethods

Defined in:
lib/clearance/user.rb

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/clearance/user.rb', line 54

def authenticated?(password)
  encrypted_password == encrypt(password)
end

#confirm_email!Object



75
76
77
78
79
# File 'lib/clearance/user.rb', line 75

def confirm_email!
  self.email_confirmed  = true
  self.token            = nil
  save(false)
end

#encrypt(string) ⇒ Object



58
59
60
# File 'lib/clearance/user.rb', line 58

def encrypt(string)
  generate_hash("--#{salt}--#{string}--")
end

#forget_me!Object



70
71
72
73
# File 'lib/clearance/user.rb', line 70

def forget_me!
  clear_token
  save(false)
end

#forgot_password!Object



81
82
83
84
# File 'lib/clearance/user.rb', line 81

def forgot_password!
  generate_token
  save(false)
end

#remember?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/clearance/user.rb', line 62

def remember?
  token_expires_at && Time.now.utc < token_expires_at
end

#remember_me!Object



66
67
68
# File 'lib/clearance/user.rb', line 66

def remember_me!
  remember_me_until! 2.weeks.from_now.utc
end

#update_password(new_password, new_password_confirmation) ⇒ Object



86
87
88
89
90
91
# File 'lib/clearance/user.rb', line 86

def update_password(new_password, new_password_confirmation)
  self.password              = new_password
  self.password_confirmation = new_password_confirmation
  clear_token if valid?
  save
end