Sha256: 190e114a8d69590a0040825d8e819bffed35491959d0f874d0a08eb6a00dda53

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

module Shoppe
  class User < ActiveRecord::Base

    self.table_name = 'shoppe_users'
  
    has_secure_password
  
    # Validations
    validates :first_name, :presence => true
    validates :last_name, :presence => true
    validates :email_address, :presence => true
  
    # The user's first name & last name concatenated
    #
    # @return [String]
    def full_name
      "#{first_name} #{last_name}"
    end
  
    # The user's first name & initial of last name concatenated
    #
    # @return [String]
    def short_name
      "#{first_name} #{last_name[0,1]}"
    end
  
    # Reset the user's password to something random and e-mail it to them
    def reset_password!
      self.password = SecureRandom.hex(8)
      self.password_confirmation = self.password
      self.save!
      Shoppe::UserMailer.new_password(self).deliver_now
    end
  
    # Attempt to authenticate a user based on email & password. Returns the 
    # user if successful otherwise returns false.
    #
    # @param email_address [String]
    # @param paassword [String]
    # @return [Shoppe::User]
    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
  
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
shoppe-1.1.1 app/models/shoppe/user.rb
shoppe-1.1.0 app/models/shoppe/user.rb
shoppe-1.0.9 app/models/shoppe/user.rb
shoppe-1.0.8 app/models/shoppe/user.rb
kylekthompson-shoppe-1.0.7 app/models/shoppe/user.rb
shoppe-1.0.7 app/models/shoppe/user.rb
shoppe-1.0.6 app/models/shoppe/user.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/shoppe-1.0.5/app/models/shoppe/user.rb
shoppe-1.0.5 app/models/shoppe/user.rb