UserIdentity.php 890 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * UserIdentity represents the data needed to identity a user.
  4. * It contains the authentication method that checks if the provided
  5. * data can identity the user.
  6. */
  7. class UserIdentity extends CUserIdentity
  8. {
  9. private $_id;
  10. /**
  11. * Authenticates a user.
  12. * @return boolean whether authentication succeeds.
  13. */
  14. public function authenticate()
  15. {
  16. $user=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
  17. if($user===null)
  18. $this->errorCode=self::ERROR_USERNAME_INVALID;
  19. else if(!$user->validatePassword($this->password))
  20. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  21. else
  22. {
  23. $this->_id=$user->id;
  24. $this->username=$user->username;
  25. $this->errorCode=self::ERROR_NONE;
  26. }
  27. return $this->errorCode==self::ERROR_NONE;
  28. }
  29. /**
  30. * @return integer the ID of the user record
  31. */
  32. public function getId()
  33. {
  34. return $this->_id;
  35. }
  36. }