Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 178
- Log:
Hub integration of Beast forum. Completed styling for RISC OS Open site.
Removed reliance on JavaScript. Added Textile hints to various views.
Added bespoke utility code used to port over RForum data for posterity;
note the rather large bug that it ignores the deleted flag on RForum
data.Some amount of testing carried out on Firefox, Opera and Netsurf. Looks
OK so far, but there are definitely some aesthetic kinks to work out
still and doubtless some operational bugs will surface once it goes
live and is subjected to more intensive real world use.
- Author:
- rool
- Date:
- Mon Mar 12 00:19:40 +0000 2007
- Size:
- 3373 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 | # Commented out lots of stuff here. Users are built through |
13 | # Hub now, so many of the requirements are invalid anyway. The |
14 | # new replacement code is immediately below, before the old |
15 | # commented out block. |
16 | |
17 | validates_uniqueness_of :login |
18 | |
19 | # validates_presence_of :login, :email, :password_hash |
20 | # validates_length_of :login, :minimum => 2 |
21 | # validates_length_of :password, :minimum => 5, :allow_nil => true |
22 | # validates_confirmation_of :password, :on => :create |
23 | # |
24 | # # names that start with #s really upset me for some reason |
25 | # validates_format_of :login, :with => /^[a-z]{2}(?:\w+)?$/i |
26 | # |
27 | # # names that start with #s really upset me for some reason |
28 | # validates_format_of :display_name, :with => /^[a-z]{2}(?:[.'\-\w ]+)?$/i |
29 | # |
30 | # validates_uniqueness_of :login, :email, :display_name, :case_sensitive => false |
31 | # before_validation { |u| u.display_name = u.login if u.display_name.blank? } |
32 | # # first user becomes admin automatically |
33 | # before_create { |u| u.admin = u.activated = true if User.count == 0 } |
34 | # format_attribute :bio |
35 | |
36 | attr_reader :password |
37 | |
38 | # Relaxed protected attributes. Note that admin and activation flags |
39 | # can now be mass-assigned. This is only acceptable because there is |
40 | # no longer an external interface for modifying Users through the |
41 | # user controller. |
42 | |
43 | attr_protected :posts_count, :created_at, :updated_at, :last_login_at, :topics_count |
44 | |
45 | # attr_protected :admin, :posts_count, :login, :created_at, :updated_at, :last_login_at, :topics_count, :activated |
46 | |
47 | def self.currently_online |
48 | User.find(:all, :conditions => ["last_seen_at > ?", Time.now.utc-5.minutes]) |
49 | end |
50 | |
51 | # we allow false to be passed in so a failed login can check |
52 | # for an inactive account to show a different error |
53 | def self.authenticate(login, password, activated=true) |
54 | find_by_login_and_password_hash_and_activated(login, Digest::SHA1.hexdigest(password + PASSWORD_SALT), activated) |
55 | end |
56 | |
57 | def self.search(query, options = {}) |
58 | with_scope :find => { :conditions => build_search_conditions(query) } do |
59 | find :all, options |
60 | end |
61 | end |
62 | |
63 | def self.build_search_conditions(query) |
64 | query && ['LOWER(display_name) LIKE :q OR LOWER(login) LIKE :q', {:q => "%#{query}%"}] |
65 | end |
66 | |
67 | def password=(value) |
68 | return if value.blank? |
69 | write_attribute :password_hash, Digest::SHA1.hexdigest(value + PASSWORD_SALT) |
70 | @password = value |
71 | end |
72 | |
73 | def reset_login_key! |
74 | self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password_hash.to_s + rand(123456789).to_s).to_s |
75 | # this is not currently honored |
76 | self.login_key_expires_at = Time.now.utc+1.year |
77 | save! |
78 | login_key |
79 | end |
80 | |
81 | def moderator_of?(forum) |
82 | moderatorships.count(:all, :conditions => ['forum_id = ?', (forum.is_a?(Forum) ? forum.id : forum)]) == 1 |
83 | end |
84 | |
85 | def to_xml(options = {}) |
86 | options[:except] ||= [] |
87 | options[:except] << :email << :login_key << :login_key_expires_at << :password_hash |
88 | super |
89 | end |
90 | end |