| Class | User |
| In: |
app/models/user.rb
|
| Parent: | ActiveRecord::Base |
Authenticates a user by their login name and unencrypted password. Returns the user or nil.
uff. this is really an authorization, not authentication routine. We really need a Dispatch Chain here or something. This will also let us return a human error message.
# File app/models/user.rb, line 38
38: def self.authenticate(email_login, password)
39: return nil if email_login.blank? || password.blank?
40: # need to get the salt, for legacy support check login before email
41: u = find_in_state(:first, :active, :conditions => { :login => email_login }) ||
42: find_in_state(:first, :admin, :conditions => { :login => email_login }) ||
43: find_in_state(:first, :active, :conditions => { :email => email_login }) ||
44: find_in_state(:first, :admin, :conditions => { :email => email_login })
45: u && u.authenticated?(password) ? u : nil
46: end
Delete all data connected to the user.
# File app/models/user.rb, line 79
79: def destroy_data
80: item_ids_str = item_ids.join(',')
81: prompt_ids_str = prompt_ids.join(',')
82: question_ids_str = question_ids.join(',')
83: voter_ids_str = voter_ids.join(',')
84: Vote.delete_all("prompt_id IN (#{prompt_ids_str})") unless prompt_ids_str.empty?
85: unless item_ids_str.empty?
86: ActiveRecord::Base.connection.execute("DELETE FROM items_stats WHERE item_id IN (#{item_ids_str})")
87: ActiveRecord::Base.connection.execute("DELETE FROM items_votes WHERE item_id IN (#{item_ids_str})")
88: ActiveRecord::Base.connection.execute("DELETE FROM items_prompts WHERE item_id IN (#{item_ids_str})")
89: end
90: Item.delete_all("user_id=#{id}")
91: unless question_ids_str.empty?
92: Stat.delete_all("question_id IN (#{question_ids_str})")
93: ItemsQuestion.delete_all("question_id IN (#{question_ids_str})")
94: PromptRequest.delete_all("question_id IN (#{question_ids_str})")
95: Prompt.delete_all("question_id IN (#{question_ids_str})")
96: end
97: Question.delete_all("user_id=#{id}")
98: Feature.delete_all("voter_id IN (#{voter_ids_str})") unless voter_ids_str.empty?
99: Voter.delete_all("user_id=#{id}")
100: end
Delete all the user‘s items and their connections to stats, votes, prompts. Delete all stats, items_questions, prompt_requests, and prompts for the user‘s questions.
# File app/models/user.rb, line 59
59: def destroy_items
60: item_ids_str = item_ids.join(',')
61: prompt_ids_str = prompt_ids.join(',')
62: question_ids_str = question_ids.join(',')
63: Vote.delete_all("prompt_id IN (#{prompt_ids_str})") unless prompt_ids_str.empty?
64: unless item_ids_str.empty?
65: ActiveRecord::Base.connection.execute("DELETE FROM items_stats WHERE item_id IN (#{item_ids_str})")
66: ActiveRecord::Base.connection.execute("DELETE FROM items_votes WHERE item_id IN (#{item_ids_str})")
67: ActiveRecord::Base.connection.execute("DELETE FROM items_prompts WHERE item_id IN (#{item_ids_str})")
68: end
69: Item.delete_all("user_id=#{id}")
70: unless question_ids_str.empty?
71: Stat.delete_all("question_id IN (#{question_ids_str})")
72: ItemsQuestion.delete_all("question_id IN (#{question_ids_str})")
73: PromptRequest.delete_all("question_id IN (#{question_ids_str})")
74: Prompt.delete_all("question_id IN (#{question_ids_str})")
75: end
76: end
# File app/models/user.rb, line 52
52: def email=(value)
53: write_attribute :email, (value ? value.downcase : nil)
54: end
# File app/models/user.rb, line 48
48: def login=(value)
49: write_attribute :login, (value ? value.downcase : nil)
50: end