/**
  * 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()
 {
     if (strpos($this->username, "@")) {
         $user = RbacUser::model()->findByAttributes(array('user_email' => $this->username));
     } else {
         $user = RbacUser::model()->findByAttributes(array('user_name' => $this->username));
         $ph = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
     }
     if ($user === null) {
         if (strpos($this->username, "@")) {
             $this->errorCode = self::ERROR_EMAIL_INVALID;
         } else {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         }
     } elseif (!$ph->CheckPassword($this->password, $user->user_password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         //else if($user->status==0&&Yii::app()->getModule('user')->loginNotActiv==false)
         //	$this->errorCode=self::ERROR_STATUS_NOTACTIV;
     } elseif ($user->status == 0) {
         $this->errorCode = self::ERROR_STATUS_BAN;
     } else {
         $this->_id = $user->id;
         $this->username = $user->user_name;
         // title column as username
         $this->errorCode = self::ERROR_NONE;
         $employeeId = $user->employee_id;
         // Store employee ID in a session:
         //$this->setState('employeeid',$employeeId);
         Yii::app()->session['employeeid'] = $employeeId;
         Yii::app()->session['userid'] = $user->id;
         $employee = Employee::model()->findByPk($employeeId);
         Yii::app()->session['emp_fullname'] = $employee->first_name . ' ' . $employee->last_name;
         //Saving User Login & out timing
         Yii::app()->session['unique_id'] = uniqid();
         $login_time = Date('Y-m-d H:i:s');
         //UserLog::model()->saveUserlog(Yii::app()->session['unique_id'], Yii::app()->session->sessionID,Yii::app()->session['userid'],$employeeId,$user->user_name,$login_time);
     }
     return !$this->errorCode;
 }
 public function undodeleteEmployee($id)
 {
     Employee::model()->updateByPk((int) $id, array('status' => Yii::app()->params['active_status']));
     $user = RbacUser::model()->find('employee_id=:employee_id', array(':employee_id' => $id));
     $user->status = Yii::app()->params['active_status'];
     $user->save();
 }
 protected function gridLoginIDColumn($data, $row)
 {
     $model = RbacUser::model()->find('employee_id=:employeeID', array(':employeeID' => $data->id));
     echo ucwords($model->user_name);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = RbacUser::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }