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)


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

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

#confirm_email!Object

Confirm my email.

Examples:

user.confirm_email!


121
122
123
124
125
# File 'lib/clearance/user.rb', line 121

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!


131
132
133
134
# File 'lib/clearance/user.rb', line 131

def forgot_password!
  generate_confirmation_token
  save(false)
end

#remember_me!Object

Remember me for a year.

Examples:

user.remember_me!
cookies[:remember_token] = {
  :value   => user.remember_token,
  :expires => user.remember_token_expires_at
}


112
113
114
115
# File 'lib/clearance/user.rb', line 112

def remember_me!
  self.remember_token = encrypt("--#{Time.now.utc}--#{password}--")
  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



142
143
144
145
146
147
148
149
# File 'lib/clearance/user.rb', line 142

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