Module: BlueLightSpecial::User::InstanceMethods

Defined in:
lib/blue_light_special/user.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns true if the user is an admin.

Returns:

  • (Boolean)


163
164
165
# File 'lib/blue_light_special/user.rb', line 163

def admin?
  self.role == Admin
end

#authenticated?(password) ⇒ true, false

Am I authenticated with given password?

Examples:

user.authenticated?('password')

Parameters:

  • plain-text (String)

    password

Returns:

  • (true, false)


88
89
90
# File 'lib/blue_light_special/user.rb', line 88

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

#confirm_email!Object

Confirm my email.

Examples:

user.confirm_email!


126
127
128
129
130
# File 'lib/blue_light_special/user.rb', line 126

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

#facebook_user?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/blue_light_special/user.rb', line 156

def facebook_user?
  !self.facebook_uid.blank?
end

#forgot_password!Object

Mark my account as forgotten password.

Examples:

user.forgot_password!


136
137
138
139
# File 'lib/blue_light_special/user.rb', line 136

def forgot_password!
  generate_password_reset_token
  save(false)
end

#nameObject

Returns the user’s full name.



170
171
172
# File 'lib/blue_light_special/user.rb', line 170

def name
  "#{self.first_name} #{self.last_name}"
end

#remember_me!Object

Deprecated.

Set the remember token.



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

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!


117
118
119
120
# File 'lib/blue_light_special/user.rb', line 117

def reset_remember_token!
  generate_remember_token
  save(false)
end

#suppress_receive_welcome_email?Boolean

Don’t send welcome email if email already confirmed, or use is a facebook connect user

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
# File 'lib/blue_light_special/user.rb', line 94

def suppress_receive_welcome_email?
  return true if email_confirmed?
  if self.facebook_uid.present?
    self.email_confirmed    = true
    self.confirmation_token = nil
    self.save
    return true
  end
  return 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



147
148
149
150
151
152
153
154
# File 'lib/blue_light_special/user.rb', line 147

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