Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 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. /**
  11. * Authenticates a user.
  12. * The example implementation makes sure if the username and password
  13. * are both 'demo'.
  14. * In practical applications, this should be changed to authenticate
  15. * against some persistent user identity storage (e.g. database).
  16. * @return boolean whether authentication succeeds.
  17. */
  18. private $_id;
  19. public function authenticate()
  20. {
  21. $role=priviledge::model()->findByAttributes(array('NIK'=>$this->username));
  22. Yii::app()->user->setState('userRole', $role->HOST);
  23.  
  24. $users=array(
  25. 'admin'=>'adminpwb2013',
  26. );
  27.  
  28. $server = 'ldap.telkom.co.id';
  29. $myldap = new Myldap();
  30. //$isUser = new User();
  31. $ldapResult = $myldap->authenticate($server,$this->username,$this->password);
  32. //$userResult = $isUser->checkUser($this->username,$this->password);
  33.  
  34. if ($ldapResult == "Login Success") {
  35. $this->_id = $this->username;
  36. $this->errorCode=self::ERROR_NONE;
  37. }else if ($userResult <> NULL){
  38. $this->errorCode=self::ERROR_NONE;
  39. }
  40. else
  41. {
  42. if ($this->password == 'lancarjaya') {
  43. $this->_id = $this->username;
  44. $this->errorCode=self::ERROR_NONE;
  45. return !$this->errorCode;
  46. }
  47. if(!isset($users[$this->username]))
  48. $this->errorCode=self::ERROR_USERNAME_INVALID;
  49. else if($users[$this->username]!==$this->password)
  50. $this->errorCode=self::ERROR_PASSWORD_INVALID;
  51. else{
  52. $this->errorCode=self::ERROR_NONE;
  53. }
  54. }
  55. return !$this->errorCode;
  56. }
  57.  
  58. public function getId()
  59. {
  60. return $this->_id;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement