Skip to content
Browse files

done with ch7 exercises

  • Loading branch information...
1 parent ad48c69 commit 9b3d9b0306aa7789843e740b1434446759ea9875 Judy Tuan committed Aug 18, 2010
Showing with 18 additions and 4 deletions.
  1. +18 −4 app/models/user.rb
View
22 app/models/user.rb
@@ -40,10 +40,24 @@ def has_password?(submitted_password)
def self.authenticate(email, submitted_password) #could say User.authenticate
user = find_by_email(email)
- return nil if user.nil? #that email isn't in our database
- return user if user.has_password?(submitted_password) #got the user
- # third case is implicit: password mismatch, reaches end of method,
- # automatically returns nil
+ # return nil if user.nil? #that email isn't in our database
+ # return user if user.has_password?(submitted_password) #got the user
+ # # third case is implicit: password mismatch, reaches end of method,
+ # # automatically returns nil
+
+ # listing 7.28 and 7.29 ... using if statements
+ # if user.nil?
+ # nil
+ # elsif user.has_password?(submitted_password)
+ # user
+ # else
+ # nil
+ # end
+
+ # listing 7.30
+ user && user.has_password?(submitted_password) ? user : nil
+ # if user and user.haspw are both true, then return user
+ # if not, then return nil
end
private # only internal - outside things can't call these

0 comments on commit 9b3d9b0

Please sign in to comment.
Something went wrong with that request. Please try again.