Advertisement
Guest User

loginModel

a guest
Sep 16th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <?php
  2. /**
  3. * LoginForm class.
  4. * LoginForm is the data structure for keeping
  5. * user login form data. It is used by the 'login' action of 'SiteController'.
  6. */
  7. class Login extends CFormModel
  8. {
  9. public $username;
  10. public $password;
  11. //public $rememberMe;
  12.  
  13. private $_identity;
  14.  
  15. /**
  16. * Declares the validation rules.
  17. * The rules state that username and password are required,
  18. * and password needs to be authenticated.
  19. */
  20. public function rules()
  21. {
  22. return array(
  23. // username and password are required
  24. array('username, password', 'required'),
  25. // password needs to be authenticated
  26. array('password', 'authenticate'),
  27. );
  28. }
  29.  
  30. /**
  31. * Declares attribute labels.
  32. */
  33. // public function attributeLabels()
  34. // {
  35. // return array(
  36. // 'rememberMe'=>'Remember me next time',
  37. // );
  38. // }
  39.  
  40. /**
  41. * Authenticates the password.
  42. * This is the 'authenticate' validator as declared in rules().
  43. */
  44. public function authenticate($attribute,$params)
  45. {
  46. if(!$this->hasErrors())
  47. {
  48. $this->_identity=new UserIdentity($this->username,$this->password);
  49. if(!$this->_identity->authenticate())
  50. $this->addError('password','Incorrect username or password.');
  51. }
  52. }
  53.  
  54. /**
  55. * Logs in the user using the given username and password in the model.
  56. * @return boolean whether login is successful
  57. */
  58. public function login(){
  59. $session = Yii::app()->session;
  60. $connection=Yii::app()->db;
  61. $userLogin = $this->username;
  62. $passLogin = md5($this->password);
  63. $sql = "SELECT * FROM VU00004 WHERE MUUSER='$userLogin' and MUPASS='$passLogin' and MUSTAT='1'";
  64. //echo $sql;
  65. $command=$connection->createCommand($sql);
  66. $dataReader=$command->query();
  67. $no=0;
  68. while(($row=$dataReader->read())!==false) {
  69. //Yii::app()->session['sessUser']=$row['MUUSER'];
  70. //Yii::app()->session['sessPass']=$row['MUPASS'];
  71. //Yii::app()->session['sessNIK']=$row['MUNIK'];
  72. $session['sessUser'] = $row['MUUSER'];
  73. $session['sessPass'] = $row['MUPASS'];
  74. $session['sessNIK'] = $row['MUNIK'];
  75. $no++;
  76. }
  77. if($no<1){
  78. $this->addError('password','Incorrect username or password.');
  79. }else{
  80. return true;
  81. }
  82. // if($this->_identity===null){
  83. // $this->_identity=new UserIdentity($this->username,$this->password);
  84. // $this->_identity->authenticate();
  85. // }
  86. // if($this->_identity->errorCode===UserIdentity::ERROR_NONE){
  87. // $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
  88. // //$duration=3600*24*30;
  89. // Yii::app()->user->login($this->_identity,$duration);
  90. // return true;
  91. // }
  92. // else
  93. // return false;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement