Example #1
0
 /**
  * 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()
 {
     $result = Managers::model()->find('name=? and is_quit=?', array($this->username, "0"));
     if ($result) {
         if ($result->password == md5($this->username . md5($this->password))) {
             $this->_id = $result->id;
             $this->errorCode = self::ERROR_NONE;
             $token = md5($result->id . $this->password);
             //Yii::app()->cache_redis->set($result->id.'.UserToken',$token);
             $store = Store::model()->findAll('manager=:id', array(':id' => $result->id));
             $store_ids = array();
             if ($store) {
                 foreach ($store as $key => $val) {
                     $store_ids[] = $val->id;
                 }
             }
             Yii::app()->user->setState('token', $token);
             Yii::app()->user->setState('info', $result);
             Yii::app()->user->setState('store', $store);
             Yii::app()->user->setState('store_ids', $store_ids);
         } else {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         }
     } else {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     }
     return !$this->errorCode;
 }
Example #2
0
 public function checkPwd($id, $pwd)
 {
     $model = Managers::model()->findByPk($id);
     $entry_pwd = md5($model->name . md5($pwd));
     if ($entry_pwd == $model->password) {
         return true;
     } else {
         $this->addError('old_pwd', '密码错误,请重新再试!');
         return false;
     }
 }
Example #3
0
 public function actionChange($id)
 {
     $model = new ChangeForm();
     if ($_POST['ChangeForm']) {
         $model->setAttributes($_POST['ChangeForm']);
         if ($model->validate() && $model->checkPwd($id, $_POST['ChangeForm']['old_pwd'])) {
             $userinfo = Managers::model()->findByPk($id);
             $new_password = md5($userinfo->name . md5($_POST['ChangeForm']['sure_pwd']));
             if (Managers::model()->updateByPk($id, ['password' => $new_password])) {
                 Yii::app()->user->logout();
                 Yii::app()->session->destroy();
                 $this->redirect(Yii::app()->user->loginUrl);
             }
         }
     }
     $info = Managers::model()->loadStaffModel($id);
     $this->render('change', ['model' => $model, 'info' => $info]);
 }
Example #4
0
 public function actionChange()
 {
     $id = $this->_get('id');
     if ($id) {
         $accessKey = Yii::app()->params['qiniu']['accessKey'];
         $secretKey = Yii::app()->params['qiniu']['secretKey'];
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 'urtime1';
         $token = $auth->uploadToken($bucket);
         $uploadMgr = new UploadManager();
         $model = Store::model()->findByPk($id);
         $bussiness_license = array();
         $images = array();
         if ($model->bussiness_license) {
             $bussiness_license = json_decode($model->bussiness_license);
         }
         if ($model->images_str) {
             $image = json_decode($model->images_str);
             if ($image) {
                 foreach ($image as $key => $val) {
                     $images = Yii::app()->params['qiniu']['host'] . $val;
                 }
             }
         }
         if ($_POST['Store']) {
             //上传logo
             if ($_FILES['image']['name'] != null) {
                 $images = array($_FILES['image']);
                 $images = $this->setImageInformation($images, $token, $uploadMgr);
                 if ($images) {
                     $_POST['Store']['image'] = $images[0];
                 }
                 unset($_FILES['image']);
             } else {
                 unset($_FILES['image']);
             }
             //上传营业执照
             if ($_FILES['bussiness_license1']['name'] != null || $_FILES['bussiness_license2']['name'] != null) {
                 if ($model->bussiness_license) {
                     if ($_FILES['bussiness_license1']['name'] != null || $_FILES['bussiness_license2']['name'] == null) {
                         $bussiness = json_decode($model->bussiness_license);
                         $images = array($_FILES['bussiness_license1']);
                         $images = $this->setImageInformation($images, $token, $uploadMgr);
                         $bussiness[0] = $images[0];
                         $_POST['Store']['bussiness_license'] = json_encode($bussiness);
                         //$images_str;
                     } else {
                         if ($_FILES['bussiness_license1']['name'] == null || $_FILES['bussiness_license2']['name'] != null) {
                             $bussiness = json_decode($model->bussiness_license);
                             $images = array($_FILES['bussiness_license2']);
                             $images = $this->setImageInformation($images, $token, $uploadMgr);
                             $bussiness[1] = $images[0];
                             $_POST['Store']['bussiness_license'] = json_encode($bussiness);
                             //$images_str;
                         } else {
                             $images = array($_FILES['bussiness_license1'], $_FILES['bussiness_license2']);
                             $images = $this->setImageInformation($images, $token, $uploadMgr);
                             if ($images) {
                                 // $images_str = implode(',',$images);
                                 $_POST['Store']['bussiness_license'] = json_encode($images);
                                 //$images_str;
                             }
                         }
                     }
                 } else {
                     $images = array($_FILES['bussiness_license1'], $_FILES['bussiness_license2']);
                     $images = $this->setImageInformation($images, $token, $uploadMgr);
                     if ($images) {
                         // $images_str = implode(',',$images);
                         $_POST['Store']['bussiness_license'] = json_encode($images);
                         //$images_str;
                     }
                 }
                 unset($_FILES['bussiness_license1']);
                 unset($_FILES['bussiness_license2']);
             } else {
                 unset($_FILES['bussiness_license1']);
                 unset($_FILES['bussiness_license2']);
             }
             //上传介绍图片
             if ($_FILES['upImage']['name'] != null) {
                 $images = $this->setImageInformation($images, $token, $uploadMgr);
                 if ($images) {
                     //$images_str = implode(',',$images);
                     $_POST['Store']['images_str'] = json_encode($images);
                     //$images_str;
                 }
             }
             $model->attributes = $_POST['Store'];
             if ($model->validate() && $model->save()) {
                 //$this->redirect('site/index');
                 Yii::app()->user->setFlash('create', '成功', '失败');
                 // Yii::app()->end();
                 $this->redirect(array('/store/view'));
             }
         }
         $is_manager = Yii::app()->user->getState("info")->authority >= 1 ? 1 : 0;
         //             var_dump($images);
         //             exit;
         $managers = Managers::model()->loadStaffAllModel();
         $this->render('change', ['model' => $model, 'bussiness_license' => $bussiness_license, 'images' => $images, 'managers' => $managers, 'is_manager' => $is_manager]);
     } else {
         $this->redirect(array('/site/index'));
     }
 }