Sha256: a3b98652d42a0661ae725f766220fa8f0c09fc6c59a72fa9505fc9818dc1e8d1
Contents?: true
Size: 1.91 KB
Versions: 4
Compression:
Stored size: 1.91 KB
Contents
require 'digest/sha1' class User < ActiveRecord::Base include Authentication include Authentication::ByPassword include Authentication::ByCookieToken validates_presence_of :login validates_length_of :login, :within => 3..255 validates_uniqueness_of :login validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true validates_length_of :name, :maximum => 255 validates_presence_of :email validates_length_of :email, :within => 6..255 validates_uniqueness_of :email validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message belongs_to :account belongs_to :role has_many :settings, :through=>:account has_many :currencies, :through=>:account has_many :tlds, :through=>:account has_many :userfieldnames, :through=>:account before_create :make_activation_code attr_accessible :login, :email, :name, :password, :password_confirmation def activate! @activated = true self.activated_at = Time.now.utc self.activation_code = nil save(false) end def recently_activated? @activated end def active? activation_code.nil? end def self.authenticate(login, password) return nil if login.blank? || password.blank? u = find :first, :conditions => ['login = ? and activated_at IS NOT NULL', login] u && u.authenticated?(password) ? u : nil end def login=(value) write_attribute :login, (value ? value.downcase : nil) end def email=(value) write_attribute :email, (value ? value.downcase : nil) end protected def make_activation_code self.activation_code = self.class.make_token end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
smukherjee-openbill-0.1.5 | app/models/user.rb |
smukherjee-openbill-0.1.6 | app/models/user.rb |
openbill-0.1.5 | app/models/user.rb |
openbill-0.1.6 | app/models/user.rb |