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) ⇒ Shoppe::User

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


41
42
43
44
45
46
# File 'app/models/shoppe/user.rb', line 41

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_nameString

The user's first name & last name concatenated


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

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


28
29
30
31
32
33
# File 'app/models/shoppe/user.rb', line 28

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

#short_nameString

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


23
24
25
# File 'app/models/shoppe/user.rb', line 23

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