Class: Shoppe::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shoppe/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(email_address, password) ⇒ Object

Attempt to authenticate a user based on email & password. Returns the user if successful otherwise returns false.



34
35
36
37
38
39
# File 'app/models/shoppe/user.rb', line 34

def self.authenticate(email_address, password)
  user = self.where(:email_address => email_address).first
  return false if user.nil?
  return false unless user.authenticate(password)
  user
end

Instance Method Details

#full_nameObject

The user’s first name & last name concatenated



15
16
17
# File 'app/models/shoppe/user.rb', line 15

def full_name
  "#{first_name} #{last_name}"
end

#reset_password!Object

Reset the user’s password to something random and e-mail it to them



25
26
27
28
29
30
# File 'app/models/shoppe/user.rb', line 25

def reset_password!
  self.password = SecureRandom.hex(8)
  self.password_confirmation = self.password
  self.save!
  Shoppe::UserMailer.new_password(self).deliver
end

#short_nameObject

The user’s first name & initial of last name concatenated



20
21
22
# File 'app/models/shoppe/user.rb', line 20

def short_name
  "#{first_name} #{last_name[0,1]}"
end