Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 173
- Log:
Updated to latest release of Beast according to the "getting started with
Beast" guide at:http://beast.caboo.se/forums/1/topics/381
This check-in includes frozen Edge Rails and has the beginnings of
configuration for the ROOL site included.
- Author:
- rool
- Date:
- Fri Mar 02 15:59:12 +0000 2007
- Size:
- 2778 Bytes
1 | require 'digest/sha1' |
2 | |
3 | class User < ActiveRecord::Base |
4 | has_many :moderatorships, :dependent => :destroy |
5 | has_many :forums, :through => :moderatorships, :order => 'forums.name' |
6 | |
7 | has_many :posts |
8 | has_many :topics |
9 | has_many :monitorships |
10 | has_many :monitored_topics, :through => :monitorships, :conditions => ['monitorships.active = ?', true], :order => 'topics.replied_at desc', :source => :topic |
11 | |
12 | validates_presence_of :login, :email, :password_hash |
13 | validates_length_of :login, :minimum => 2 |
14 | validates_length_of :password, :minimum => 5, :allow_nil => true |
15 | validates_confirmation_of :password, :on => :create |
16 | |
17 | # names that start with #s really upset me for some reason |
18 | validates_format_of :login, :with => /^[a-z]{2}(?:\w+)?$/i |
19 | |
20 | # names that start with #s really upset me for some reason |
21 | validates_format_of :display_name, :with => /^[a-z]{2}(?:[.'\-\w ]+)?$/i |
22 | |
23 | validates_uniqueness_of :login, :email, :display_name, :case_sensitive => false |
24 | before_validation { |u| u.display_name = u.login if u.display_name.blank? } |
25 | # first user becomes admin automatically |
26 | before_create { |u| u.admin = u.activated = true if User.count == 0 } |
27 | format_attribute :bio |
28 | |
29 | attr_reader :password |
30 | attr_protected :admin, :posts_count, :login, :created_at, :updated_at, :last_login_at, :topics_count, :activated |
31 | |
32 | def self.currently_online |
33 | User.find(:all, :conditions => ["last_seen_at > ?", Time.now.utc-5.minutes]) |
34 | end |
35 | |
36 | # we allow false to be passed in so a failed login can check |
37 | # for an inactive account to show a different error |
38 | def self.authenticate(login, password, activated=true) |
39 | find_by_login_and_password_hash_and_activated(login, Digest::SHA1.hexdigest(password + PASSWORD_SALT), activated) |
40 | end |
41 | |
42 | def self.search(query, options = {}) |
43 | with_scope :find => { :conditions => build_search_conditions(query) } do |
44 | find :all, options |
45 | end |
46 | end |
47 | |
48 | def self.build_search_conditions(query) |
49 | query && ['LOWER(display_name) LIKE :q OR LOWER(login) LIKE :q', {:q => "%#{query}%"}] |
50 | end |
51 | |
52 | def password=(value) |
53 | return if value.blank? |
54 | write_attribute :password_hash, Digest::SHA1.hexdigest(value + PASSWORD_SALT) |
55 | @password = value |
56 | end |
57 | |
58 | def reset_login_key! |
59 | self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password_hash.to_s + rand(123456789).to_s).to_s |
60 | # this is not currently honored |
61 | self.login_key_expires_at = Time.now.utc+1.year |
62 | save! |
63 | login_key |
64 | end |
65 | |
66 | def moderator_of?(forum) |
67 | moderatorships.count(:all, :conditions => ['forum_id = ?', (forum.is_a?(Forum) ? forum.id : forum)]) == 1 |
68 | end |
69 | |
70 | def to_xml(options = {}) |
71 | options[:except] ||= [] |
72 | options[:except] << :email << :login_key << :login_key_expires_at << :password_hash |
73 | super |
74 | end |
75 | end |