Advertisement
eerrtt

Untitled

Mar 18th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * UserIdentity represents the data needed to identity a user.
  5. * It contains the authentication method that checks if the provided
  6. * data can identity the user.
  7. */
  8. class UserIdentity extends CUserIdentity
  9. {
  10. private $_id;
  11. const ERROR_EMAIL_INVALID=3;
  12. const ERROR_STATUS_NOTACTIV=4;
  13. const ERROR_STATUS_BAN=5;
  14.  
  15. const ERROR_PHONE_INVALID=6;
  16. /**
  17. * Authenticates a user.
  18. * The example implementation makes sure if the username and password
  19. * are both 'demo'.
  20. * In practical applications, this should be changed to authenticate
  21. * against some persistent user identity storage (e.g. database).
  22. * @return boolean whether authentication succeeds.
  23. */
  24. public function authenticate($force = false)
  25. {
  26. $user=User::model()->notsafe()->findByAttributes(array('email'=>$this->username));
  27. if ($force == true && $user !== null) {
  28. $this->errorCode = self::ERROR_NONE;
  29. $this->_id = $user->id;
  30. $this->username=$user->email;
  31. return true;
  32. }
  33.  
  34. if($user===null)
  35. $this->errorCode=self::ERROR_EMAIL_INVALID;
  36. else if(!$user->validatePassword($this->password))
  37. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  38. else if($user->status==0&&Yii::app()->getModule('user')->loginNotActiv==false)
  39. $this->errorCode=self::ERROR_STATUS_NOTACTIV;
  40. else if($user->status==-1)
  41. $this->errorCode=self::ERROR_STATUS_BAN;
  42. else {
  43. $this->_id=$user->id;
  44. $this->username=$user->email;
  45. $this->errorCode=self::ERROR_NONE;
  46. }
  47. return !$this->errorCode;
  48. }
  49.  
  50. public function hybridauth($username)
  51. {
  52. $user=User::model()->find("email = '" . $username . "'");
  53. if ( $user === null )
  54. $this->errorCode = self::ERROR_USERNAME_INVALID;
  55. else
  56. {
  57. $this->_id = $user->id;
  58. $this->username = $user->email;
  59. $this->errorCode = self::ERROR_NONE;
  60. }
  61. return $this->errorCode == self::ERROR_NONE;
  62. }
  63.  
  64. /**
  65. * @return integer the ID of the user record
  66. */
  67. public function getId()
  68. {
  69. return $this->_id;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement