UserIdentity.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /**
  10. * Authenticates a user.
  11. * The example implementation makes sure if the username and password
  12. * are both 'demo'.
  13. * In practical applications, this should be changed to authenticate
  14. * against some persistent user identity storage (e.g. database).
  15. * @return boolean whether authentication succeeds.
  16. */
  17. private $_id; //对应useradmin_id
  18. public function authenticate()
  19. {
  20. $record = Useradmin::model()->findByAttributes(array('username' => $this->username));
  21. if ($record === null){
  22. $this->errorCode = self::ERROR_USERNAME_INVALID;
  23. }
  24. else if ($record->password !== md5($this->password)){
  25. $this->errorCode = self::ERROR_PASSWORD_INVALID;
  26. }
  27. else
  28. {
  29. $this->_id=$record->id;
  30. $this->setState('_id', $record->id);
  31. $this->setState('username', $record->username); //这个用户生成激活码判断
  32. $this->setState('password', $record->password); //这个用户生成激活码判断
  33. $this->errorCode = self::ERROR_NONE;
  34. }
  35. return !$this->errorCode;
  36. }
  37. public function getId()
  38. {
  39. return $this->_id;
  40. }
  41. }