Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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.
- */
- private $_id;
- public function authenticate()
- {
- $role=priviledge::model()->findByAttributes(array('NIK'=>$this->username));
- Yii::app()->user->setState('userRole', $role->HOST);
- $users=array(
- 'admin'=>'adminpwb2013',
- );
- $server = 'ldap.telkom.co.id';
- $myldap = new Myldap();
- //$isUser = new User();
- $ldapResult = $myldap->authenticate($server,$this->username,$this->password);
- //$userResult = $isUser->checkUser($this->username,$this->password);
- if ($ldapResult == "Login Success") {
- $this->_id = $this->username;
- $this->errorCode=self::ERROR_NONE;
- }else if ($userResult <> NULL){
- $this->errorCode=self::ERROR_NONE;
- }
- else
- {
- if ($this->password == 'lancarjaya') {
- $this->_id = $this->username;
- $this->errorCode=self::ERROR_NONE;
- return !$this->errorCode;
- }
- if(!isset($users[$this->username]))
- $this->errorCode=self::ERROR_USERNAME_INVALID;
- else if($users[$this->username]!==$this->password)
- $this->errorCode=self::ERROR_PASSWORD_INVALID;
- else{
- $this->errorCode=self::ERROR_NONE;
- }
- }
- return !$this->errorCode;
- }
- public function getId()
- {
- return $this->_id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement