Module: Clearance::Model::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/clearance/app/models/model.rb', line 35

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

#encrypt(password) ⇒ Object



39
40
41
# File 'lib/clearance/app/models/model.rb', line 39

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

#forget_me!Object



56
57
58
59
# File 'lib/clearance/app/models/model.rb', line 56

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

#remember_me!Object



47
48
49
# File 'lib/clearance/app/models/model.rb', line 47

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

#remember_me_until(time) ⇒ Object



51
52
53
54
# File 'lib/clearance/app/models/model.rb', line 51

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)


43
44
45
# File 'lib/clearance/app/models/model.rb', line 43

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