Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 2785 Bytes
1 | require 'digest/sha1' |
2 | |
3 | # this model expects a certain database layout and its based on the name/login pattern. |
4 | class User < CachedModel |
5 | has_many :notifications, :foreign_key => 'notify_user_id' |
6 | has_many :notify_contents, :through => :notifications, |
7 | :source => 'notify_content', |
8 | :uniq => true |
9 | |
10 | has_many :articles, :order => 'created_at DESC' do |
11 | def published |
12 | find_published(:all, :order => 'created_at DESC') |
13 | end |
14 | end |
15 | |
16 | # echo "typo" | sha1sum - |
17 | @@salt = '20ac4d290c2293702c64b3b287ae5ea79b26a5c1' |
18 | cattr_accessor :salt |
19 | |
20 | # Authenticate a user. |
21 | # |
22 | # Example: |
23 | # @user = User.authenticate('bob', 'bobpass') |
24 | # |
25 | def self.authenticate(login, pass) |
26 | find(:first, |
27 | :conditions => ["login = ? AND password = ?", login, sha1(pass)]) |
28 | end |
29 | |
30 | def self.authenticate?(login, pass) |
31 | user = self.authenticate(login, pass) |
32 | return false if user.nil? |
33 | return true if user.login == login |
34 | |
35 | false |
36 | end |
37 | |
38 | def self.find_by_permalink(permalink) |
39 | self.find_by_login(permalink) |
40 | end |
41 | |
42 | # Let's be lazy, no need to fetch the counters, rails will handle it. |
43 | def self.find_all_with_article_counters(ignored_arg) |
44 | find(:all) |
45 | end |
46 | |
47 | def self.to_prefix |
48 | 'author' |
49 | end |
50 | |
51 | def password=(newpass) |
52 | @password = newpass |
53 | end |
54 | |
55 | def password(cleartext = nil) |
56 | if cleartext |
57 | @password.to_s |
58 | else |
59 | @password || read_attribute("password") |
60 | end |
61 | end |
62 | |
63 | def article_counter |
64 | articles.size |
65 | end |
66 | |
67 | def display_name |
68 | name |
69 | end |
70 | |
71 | def permalink |
72 | login |
73 | end |
74 | |
75 | protected |
76 | |
77 | # Apply SHA1 encryption to the supplied password. |
78 | # We will additionally surround the password with a salt |
79 | # for additional security. |
80 | def self.sha1(pass) |
81 | Digest::SHA1.hexdigest("#{salt}--#{pass}--") |
82 | end |
83 | |
84 | before_create :crypt_password |
85 | |
86 | # Before saving the record to database we will crypt the password |
87 | # using SHA1. |
88 | # We never store the actual password in the DB. |
89 | def crypt_password |
90 | write_attribute "password", self.class.sha1(password(true)) |
91 | @password = nil |
92 | end |
93 | |
94 | before_update :crypt_unless_empty |
95 | |
96 | # If the record is updated we will check if the password is empty. |
97 | # If its empty we assume that the user didn't want to change his |
98 | # password and just reset it to the old value. |
99 | def crypt_unless_empty |
100 | if password(true).empty? |
101 | user = self.class.find(self.id) |
102 | self.password = user.password |
103 | else |
104 | write_attribute "password", self.class.sha1(password(true)) |
105 | @password = nil |
106 | end |
107 | end |
108 | |
109 | validates_uniqueness_of :login, :on => :create |
110 | validates_length_of :password, :within => 5..40, :on => :create |
111 | validates_presence_of :login |
112 | |
113 | validates_confirmation_of :password, :if=> Proc.new { |u| u.password.size > 0} |
114 | validates_length_of :login, :within => 3..40 |
115 | end |