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)


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

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

#confirm_email!Object

Confirm my email.

Examples:

user.confirm_email!


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

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

#forgot_password!Object

Mark my account as forgotten password.

Examples:

user.forgot_password!


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

def forgot_password!
  generate_confirmation_token
  save(false)
end

#remember_me!Object

Deprecated.

Set the remember token.



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

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!


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

def reset_remember_token!
  generate_remember_token
  save(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



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

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