Module: Clearance::User

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
lib/clearance/user.rb

Defined Under Namespace

Modules: Callbacks, ClassMethods, Validations

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ true, false

Am I authenticated with given password?

Examples:

user.authenticated?('password')

Parameters:

  • plain-text (String)

    password

Returns:

  • (true, false)


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

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

#forgot_password!Object

Mark my account as forgotten password.

Examples:

user.forgot_password!


100
101
102
103
# File 'lib/clearance/user.rb', line 100

def forgot_password!
  generate_confirmation_token
  save(:validate => false)
end

#remember_me!Object

Deprecated.

Set the remember token.



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

def remember_me!
  warn "[DEPRECATION] remember_me!: use reset_remember_token! instead"
  reset_remember_token!
end

#reset_remember_token!Object

Reset the remember token.

Examples:

user.reset_remember_token!


91
92
93
94
# File 'lib/clearance/user.rb', line 91

def reset_remember_token!
  generate_remember_token
  save(:validate => false)
end

#update_password(new_password) ⇒ true, false

Update my password.

Examples:

user.update_password('new-password')

Returns:

  • (true, false)

    password was updated or not



110
111
112
113
114
115
116
117
118
# File 'lib/clearance/user.rb', line 110

def update_password(new_password)
  self.password_changing = true
  self.password          = new_password
  if valid?
    self.confirmation_token = nil
    generate_remember_token
  end
  save
end