Module: Clearance::User::InstanceMethods

Defined in:
lib/clearance/user.rb

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)


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

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

#confirm_email!Object

Confirm my email.

Examples:

user.confirm_email!


108
109
110
111
112
# File 'lib/clearance/user.rb', line 108

def confirm_email!
  self.email_confirmed    = true
  self.confirmation_token = nil
  save(:validate => false)
end

#forgot_password!Object

Mark my account as forgotten password.

Examples:

user.forgot_password!


118
119
120
121
# File 'lib/clearance/user.rb', line 118

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

#remember_me!Object

Deprecated.

Set the remember token.



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

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!


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

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

#update_password(new_password, new_password_confirmation) ⇒ true, false

Update my password.

Examples:

user.update_password('new-password', 'new-password')

Parameters:

  • password (String, String)

    and password confirmation

Returns:

  • (true, false)

    password was updated or not



129
130
131
132
133
134
135
136
# File 'lib/clearance/user.rb', line 129

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