10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/active_record/acts/muck_user.rb', line 10
def acts_as_muck_user(options = {})
has_many :permissions
has_many :roles, :through => :permissions
named_scope :by_newest, :order => "created_at DESC"
named_scope :active, :conditions => "activated_at IS NOT NULL"
named_scope :inactive, :conditions => "activated_at IS NULL"
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
belongs_to :access_code
accepts_nested_attributes_for :access_code
attr_accessor :access_code_code
email_name_regex = '[\w\.%\+\-]+'.freeze
domain_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
before_save :lower_login
class_eval <<-EOV
validates_format_of :login, :with => /^[a-z0-9-]+$/i, :message => 'may only contain letters, numbers or a hyphen.'
validates_format_of :email, :with => email_regex, :message => 'does not look like a valid email address.'
# prevents a user from submitting a crafted form that bypasses activation
attr_protected :crypted_password, :password_salt, :persistence_token, :single_access_token, :perishable_token, :login_count,
:failed_login_count, :last_request_at, :last_login_at, :current_login_at, :current_login_ip, :last_login_ip,
:terms_of_service, :time_zone, :disabled_at, :activated_at, :created_at, :updated_at
EOV
include ActiveRecord::Acts::MuckUser::InstanceMethods
extend ActiveRecord::Acts::MuckUser::SingletonMethods
end
|