123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * UserIdentity represents the data needed to identity a user.
- * It contains the authentication method that checks if the provided
- * data can identity the user.
- */
- class UserIdentity extends CUserIdentity
- {
- /**
- * Authenticates a user.
- * The example implementation makes sure if the username and password
- * are both 'demo'.
- * In practical applications, this should be changed to authenticate
- * against some persistent user identity storage (e.g. database).
- * @return boolean whether authentication succeeds.
- */
-
- public function authenticate()
- {
- $conn = Yii::app()->businessDb;
- //$coachInfo = BusinessCoach::model()->find('coach_name=:name and status=0', array(':name'=>$this->username));
- $coachInfo = BusinessCoach::model()->find('coach_name=:name', array(':name'=>$this->username));
- if(empty($coachInfo)){
- //$this->errorCode=self::ERROR_USERNAME_INVALID;
- //return false;
- return 'not exist';
- } else if ($coachInfo->status == 1) {
- return 'account is disabled';
- }
- else if($coachInfo->password !== md5(sha1($this->password))){
- $this->errorCode=self::ERROR_PASSWORD_INVALID;
- return false;
- }
- else if($coachInfo->school_id){
- $school = $conn->createCommand("select * from school where school_id = '{$coachInfo->school_id}'")->queryRow();
- if(!$school)
- return "SCHOOL_NOT_EXISTS";
-
- if($school["status"] == 1)
- return "SCHOOL_DELETED";
- }
-
- $this->errorCode=self::ERROR_NONE;
-
- //Coach::model()->updateByPk($userInfo['user_id'],array('login_time'=>time()));
- unset(Yii::app()->session['myDatebase']);
- Yii::app()->session['coachInfo'] = $coachInfo;
- Yii::app()->session['coachInfo']['default_subject_id'] = 3;
- return true;
- }
-
- /* public function authenticate()
- {
- $users=array(
- // username => password
- 'demo'=>'demo',
- 'admin'=>'admin',
- );
- if(!isset($users[$this->username]))
- $this->errorCode=self::ERROR_USERNAME_INVALID;
- elseif($users[$this->username]!==$this->password)
- $this->errorCode=self::ERROR_PASSWORD_INVALID;
- else
- $this->errorCode=self::ERROR_NONE;
- return !$this->errorCode;
- } */
- }
|