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)


27
28
29
# File 'lib/clearance/app/models/user.rb', line 27

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

#confirm_email!Object



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

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

#encrypt(string) ⇒ Object



31
32
33
# File 'lib/clearance/app/models/user.rb', line 31

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

#forget_me!Object



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

def forget_me!
  clear_token
  save(false)
end

#forgot_password!Object



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

def forgot_password!
  generate_token
  save(false)
end

#remember?Boolean

Returns:

  • (Boolean)


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

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

#remember_me!Object



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

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

#update_password(new_password, new_password_confirmation) ⇒ Object



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

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