12345678910111213141516171819202122232425262728293031323334353637 |
- class User < ActiveRecord::Base
-
-
-
- devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable, :lockable
- INVITATION_CODES = %w[try-huginn]
-
-
- attr_accessor :login
- ACCESSIBLE_ATTRIBUTES = [ :email, :username, :login, :password, :password_confirmation, :remember_me, :invitation_code ]
- attr_accessible *ACCESSIBLE_ATTRIBUTES
- attr_accessible *(ACCESSIBLE_ATTRIBUTES + [:admin]), :as => :admin
- validates_presence_of :username
- validates_uniqueness_of :username
- validates_format_of :username, :with => /\A[a-zA-Z0-9_-]{3,15}\Z/, :message => "can only contain letters, numbers, underscores, and dashes, and must be between 3 and 15 characters in length."
- validates_inclusion_of :invitation_code, :in => INVITATION_CODES, :message => "is not valid"
- has_many :events, :order => "events.created_at desc", :dependent => :delete_all, :inverse_of => :user
- has_many :agents, :order => "agents.created_at desc", :dependent => :destroy, :inverse_of => :user
-
- def self.find_first_by_auth_conditions(warden_conditions)
- conditions = warden_conditions.dup
- if login = conditions.delete(:login)
- where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
- else
- where(conditions).first
- end
- end
- end
|