Module: Clearance::App::Models::User::InstanceMethods

Defined in:
lib/clearance/app/models/user.rb

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/clearance/app/models/user.rb', line 37

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

#confirm!Object



63
64
65
# File 'lib/clearance/app/models/user.rb', line 63

def confirm!
  self.update_attribute :confirmed, true
end

#encrypt(password) ⇒ Object



41
42
43
# File 'lib/clearance/app/models/user.rb', line 41

def encrypt(password)
  Digest::SHA1.hexdigest "--#{salt}--#{password}--"
end

#forget_me!Object



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

def forget_me!
  self.update_attribute :remember_token_expires_at, nil
  self.update_attribute :remember_token, nil
end

#remember_me!Object



49
50
51
# File 'lib/clearance/app/models/user.rb', line 49

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

#remember_me_until(time) ⇒ Object



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

def remember_me_until(time)
  self.update_attribute :remember_token_expires_at, time
  self.update_attribute :remember_token, encrypt("#{email}--#{remember_token_expires_at}")
end

#remember_token?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/clearance/app/models/user.rb', line 45

def remember_token?
  remember_token_expires_at && Time.now.utc < remember_token_expires_at
end