Sha256: 2d30199e9c99307b39de36bc32236417f3cd2b23be3474a03b834ed3e4a9b5a7

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

class User < ActiveRecord::Base
  has_secure_password
  
  validates :password, presence: true, on: :create
  validates :email, presence: true, uniqueness: true, format: /@/
  
  before_create { generate_token(:auth_token) }
  
  def self.authenticate(email, password)
    user = find_by email: email
    user if user && user.authenticate(password)
  end
    
  def generate_token(column)
    begin
      self[column] = SecureRandom.urlsafe_base64
    end while User.exists?(column => self[column])
  end

  def prepare_password_reset
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authpro-0.9.0 test/rails/dummy/app/models/user.rb