UserIdentity.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. public function authenticate()
  18. {
  19. $conn = Yii::app()->businessDb;
  20. //$coachInfo = BusinessCoach::model()->find('coach_name=:name and status=0', array(':name'=>$this->username));
  21. $coachInfo = BusinessCoach::model()->find('coach_name=:name', array(':name'=>$this->username));
  22. if(empty($coachInfo)){
  23. //$this->errorCode=self::ERROR_USERNAME_INVALID;
  24. //return false;
  25. return 'not exist';
  26. } else if ($coachInfo->status == 1) {
  27. return 'account is disabled';
  28. }
  29. else if($coachInfo->password !== md5(sha1($this->password))){
  30. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  31. return false;
  32. }
  33. else if($coachInfo->school_id){
  34. $school = $conn->createCommand("select * from school where school_id = '{$coachInfo->school_id}'")->queryRow();
  35. if(!$school)
  36. return "SCHOOL_NOT_EXISTS";
  37. if($school["status"] == 1)
  38. return "SCHOOL_DELETED";
  39. }
  40. $this->errorCode=self::ERROR_NONE;
  41. //Coach::model()->updateByPk($userInfo['user_id'],array('login_time'=>time()));
  42. unset(Yii::app()->session['myDatebase']);
  43. Yii::app()->session['coachInfo'] = $coachInfo;
  44. Yii::app()->session['coachInfo']['default_subject_id'] = 3;
  45. return true;
  46. }
  47. /* public function authenticate()
  48. {
  49. $users=array(
  50. // username => password
  51. 'demo'=>'demo',
  52. 'admin'=>'admin',
  53. );
  54. if(!isset($users[$this->username]))
  55. $this->errorCode=self::ERROR_USERNAME_INVALID;
  56. elseif($users[$this->username]!==$this->password)
  57. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  58. else
  59. $this->errorCode=self::ERROR_NONE;
  60. return !$this->errorCode;
  61. } */
  62. }