Sha256: 17c2c8e591cc985706bdb93495d002b31cea2e3791438ec6a6181476ead03a8f

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module Tienda
  class User < ActiveRecord::Base

    self.table_name = 'tienda_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!
      Tienda::UserMailer.new_password(self).deliver
    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 [Tienda::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

4 entries across 4 versions & 1 rubygems

Version Path
tienda-1.1.2 app/models/tienda/user.rb
tienda-1.1.1 app/models/tienda/user.rb
tienda-1.1.0 app/models/tienda/user.rb
tienda-1.0.0 app/models/tienda/user.rb