Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(16)

Side by Side Diff: app/models/user.rb

Issue 2323: Upgrade to Rails 2 SVN Base: http://familyconnect.rubyforge.org/svn/trunk/
Patch Set: Created 1 year, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 require 'digest/sha1' 1 require 'digest/sha1'
2 2
3 # this model expects a certain database layout and its based on the name/login p attern. 3 # this model expects a certain database layout and its based on the name/login p attern.
4 class User < ActiveRecord::Base 4 class User < ActiveRecord::Base
5 has_many :news_items, :foreign_key => 'created_by_id' 5 has_many :news_items, :foreign_key => 'created_by_id'
6 6
7 file_column :portrait, :magick => { 7 file_column :portrait, :magick => {
8 :geometry => "512x512", 8 :geometry => "512x512",
9 :versions => { "thumb" => "50x50", "fullsize" => "512x512"} 9 :versions => { "thumb" => "50x50", "fullsize" => "512x512"}
10 } 10 }
11 11
12 # Please change the salt to something else, 12 # Please change the salt to something else,
13 # Every application should use a different one 13 # Every application should use a different one
14 @@salt = 'change-me' 14 @@salt = 'change-me'
15 cattr_accessor :salt 15 cattr_accessor :salt
16 16
17 # Authenticate a user. 17 # Authenticate a user.
18 # 18 #
19 # Example: 19 # Example:
20 # @user = User.authenticate('bob', 'bobpass') 20 # @user = User.authenticate('bob', 'bobpass')
21 # 21 #
22 def self.authenticate(login, pass) 22 def self.authenticate(login, pass)
23 find_first(["login = ? AND password = ?", login, sha1(pass)]) 23 User.find(:first, :conditions => ["login = ? AND password = ?", login, sha1( pass)])
24 end 24 end
25 25
26 def name 26 def name
27 [firstname, lastname].compact.join(' ') 27 [firstname, lastname].compact.join(' ')
28 end 28 end
29 29
30 def self.administrator 30 def self.administrator
31 find :first, :conditions => ["admin = ?", true] 31 User.find(:first, :conditions => ["admin = ?", true])
32 end 32 end
33 33
34 def visit_now(stamp = DateTime.now) 34 def visit_now(stamp = DateTime.now)
35 return if new_record? 35 return if new_record?
36 connection.update "UPDATE users SET visited_at = '#{stamp.to_formatted_s(:db )}' WHERE id = #{id}" 36 connection.update "UPDATE users SET visited_at = '#{stamp.to_formatted_s(:db )}' WHERE id = #{id}"
37 end 37 end
38 38
39 protected 39 protected
40 40
41 # Apply SHA1 encryption to the supplied password. 41 # Apply SHA1 encryption to the supplied password.
(...skipping 28 matching lines...) Expand all
70 70
71 validates_uniqueness_of :login, :on => :create 71 validates_uniqueness_of :login, :on => :create
72 validates_length_of :login, :within => 3..40 72 validates_length_of :login, :within => 3..40
73 validates_presence_of :login 73 validates_presence_of :login
74 validates_confirmation_of :password, :on => :create 74 validates_confirmation_of :password, :on => :create
75 validates_length_of :password, :on => :create, :within => 5..40 75 validates_length_of :password, :on => :create, :within => 5..40
76 validates_presence_of :password, :on => :create 76 validates_presence_of :password, :on => :create
77 validates_presence_of :password_confirmation, :on => :create 77 validates_presence_of :password_confirmation, :on => :create
78 validates_presence_of :email, :phone, :firstname, :lastname 78 validates_presence_of :email, :phone, :firstname, :lastname
79 end 79 end
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r483