Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 2805 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 < ActiveRecord::Base |
5 | has_and_belongs_to_many :notify_contents, :class_name => 'Content', |
6 | :join_table => 'notifications', :foreign_key => 'notify_user_id', |
7 | :association_foreign_key => 'notify_content_id', :uniq => true |
8 | |
9 | has_many :articles, :order => 'created_at DESC' do |
10 | def published |
11 | find_published(:all, :order => 'created_at DESC') |
12 | end |
13 | end |
14 | |
15 | # echo "typo" | sha1sum - |
16 | @@salt = '20ac4d290c2293702c64b3b287ae5ea79b26a5c1' |
17 | cattr_accessor :salt |
18 | |
19 | # Authenticate a user. |
20 | # |
21 | # Example: |
22 | # @user = User.authenticate('bob', 'bobpass') |
23 | # |
24 | def self.authenticate(login, pass) |
25 | find_first(["login = ? AND password = ?", login, sha1(pass)]) |
26 | end |
27 | |
28 | def self.authenticate?(login, pass) |
29 | user = self.authenticate(login, pass) |
30 | return false if user.nil? |
31 | return true if user.login == login |
32 | |
33 | false |
34 | end |
35 | |
36 | def self.find_by_permalink(permalink) |
37 | self.find_by_login(permalink) |
38 | end |
39 | |
40 | # Let's be lazy, no need to fetch the counters, rails will handle it. |
41 | def self.find_all_with_article_counters(ignored_arg) |
42 | find(:all) |
43 | end |
44 | |
45 | def self.to_prefix |
46 | 'author' |
47 | end |
48 | |
49 | def password=(newpass) |
50 | @password = newpass |
51 | end |
52 | |
53 | def password(cleartext = nil) |
54 | if cleartext |
55 | @password.to_s |
56 | else |
57 | @password || read_attribute("password") |
58 | end |
59 | end |
60 | |
61 | def article_counter |
62 | articles.size |
63 | end |
64 | |
65 | def display_name |
66 | name |
67 | end |
68 | |
69 | def permalink |
70 | login |
71 | end |
72 | |
73 | protected |
74 | |
75 | # Apply SHA1 encryption to the supplied password. |
76 | # We will additionally surround the password with a salt |
77 | # for additional security. |
78 | def self.sha1(pass) |
79 | Digest::SHA1.hexdigest("#{salt}--#{pass}--") |
80 | end |
81 | |
82 | before_create :crypt_password |
83 | |
84 | # Before saving the record to database we will crypt the password |
85 | # using SHA1. |
86 | # We never store the actual password in the DB. |
87 | def crypt_password |
88 | write_attribute "password", self.class.sha1(password(true)) |
89 | @password = nil |
90 | end |
91 | |
92 | before_update :crypt_unless_empty |
93 | |
94 | # If the record is updated we will check if the password is empty. |
95 | # If its empty we assume that the user didn't want to change his |
96 | # password and just reset it to the old value. |
97 | def crypt_unless_empty |
98 | if password(true).empty? |
99 | user = self.class.find(self.id) |
100 | self.password = user.password |
101 | else |
102 | write_attribute "password", self.class.sha1(password(true)) |
103 | @password = nil |
104 | end |
105 | end |
106 | |
107 | validates_uniqueness_of :login, :on => :create |
108 | validates_length_of :password, :within => 5..40, :on => :create |
109 | validates_presence_of :login |
110 | |
111 | validates_confirmation_of :password, :if=> Proc.new { |u| u.password.size > 0} |
112 | validates_length_of :login, :within => 3..40 |
113 | end |