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.

Parameters:

  • email_address (String)
  • paassword (String)

Returns:



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

Returns:

  • (String)


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
end

#short_nameString

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

Returns:

  • (String)


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

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