public function checkUserAdmin($accessRole_id = '')
 {
     $session = new CHttpSession();
     $session->open();
     $user_id = $session['uid'];
     //        App::pr($user_id,2);
     $user_rid = $session['rid'];
     if (!empty($user_id)) {
         if (!empty($accessRole_id)) {
             //            App::pr($accessRole_id,2);
             $record = UserMaster::model()->find("u_id = {$user_id} AND ur_id IN({$accessRole_id})");
             //            App::pr($record,2);
             if (!empty($record)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $record = UserMaster::model()->findByPk($user_id);
             if (!empty($record)) {
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         return FALSE;
     }
 }
 /**
  * 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()
 {
     //        echo '<pre>';print_r($this);
     $user = UserMaster::model()->findByAttributes(array('user_name' => $this->username));
     //        echo '<pre>';print_r($user);die;
     if ($user === null) {
         // No user found!
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->user_pass !== base64_encode($this->password)) {
             // Invalid password!
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             /**
              * @desc: Start the Session Here
              */
             $session = new CHttpSession();
             $session->open();
             /**
              * @desc: User Full Name
              */
             $session["fullname"] = ucfirst($user->first_name) . " " . ucfirst($user->last_name);
             /**
              * @desc: User ID
              */
             $session["uid"] = $user->u_id;
             /**
              * @desc: User Role Id for ACL Management
              */
             $session["rid"] = $user->ur_id;
             /**
              * @desc : User name
              */
             $session["uname"] = $user->first_name;
             $this->setState('id', $user->ur_id);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return UserType the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 public function actionChangePassword()
 {
     //        $this->heading = "Change Password";
     $model = new UserMaster();
     if (isset($_POST['UserMaster'])) {
         $currPwd = $_POST['UserMaster']['CurrentPassword'];
         $encodedPswd = base64_encode($currPwd);
         $uId = App::getSession('uid');
         $criteria = new CDbCriteria();
         $criteria->addCondition("u_id = {$uId} AND user_pass = '******'");
         $countUser = $model->findAll($criteria);
         if (!empty($countUser)) {
             $model1 = new UserMaster();
             $countUser[0]->user_pass = base64_encode($_POST['UserMaster']['NewPassword']);
             //                $model1->modified_on=date('Y-m-d h:i');
             $countUser[0]->update();
             App::setSession('upassword', md5($countUser[0]->user_pass));
             Yii::app()->user->setFlash('success', 'Password has been updated successfully..');
             $this->redirect(App::param("siteurl") . "site/index");
         } else {
             Yii::app()->user->setFlash('error', 'Current Password is incorrect..');
             $this->redirect(App::param("siteurl") . "userMaster/ChangePassword/");
         }
     }
     $this->render('changepassword', array('model' => $model));
 }
 public function actionForgetPassword()
 {
     $model = new UserMaster();
     if (isset($_POST['email']) && $_POST['email'] != '') {
         $email = trim(urldecode($_POST['email']));
         $Criteria = new CDbCriteria();
         $Criteria->condition = "user_name = '{$email}'";
         $Criteria->select = 'u_id';
         $res = [];
         $res = $model->find($Criteria);
         if (!empty($res)) {
             $res = App::objtoarray($res);
             $returnval = $this->verificationMail($email, 'forget');
             if ($returnval) {
                 echo 1;
             }
         } else {
             echo '0';
         }
     } else {
         echo '-1';
     }
     exit;
 }