示例#1
0
 /**
  * @return string|\yii\web\Response 用户登录
  */
 public function actionLogin()
 {
     $model = new YiiUser();
     $model->scenario = 'login';
     if ($model->load(Yii::$app->request->post())) {
         if ($model->login()) {
             //查询未读消息
             // $count=Msg::find()->andwhere(['tid'=>Yii::$app->user->getId(),'status'=>0])->count();
             // $session=Yii::$app->session;
             // $session->set('msg',$count);
             return $this->redirect(['index/index']);
         } else {
             return $this->render('login', ['model' => $model]);
         }
     }
     return $this->render('login', ['model' => $model]);
 }
示例#2
0
 protected function findModel($id)
 {
     if (($model = YiiUser::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
 public function createCompanyNum()
 {
     $num = YiiUser::find()->max('cnum');
     return intval($num) + 1;
 }
 /**
  * @裁剪头像
  */
 public function actionCutpic()
 {
     if (Yii::$app->request->isAjax) {
         $path = "/avatar/";
         $targ_w = $targ_h = 150;
         $jpeg_quality = 100;
         $src = Yii::$app->request->post('f');
         $src = Yii::$app->basePath . '/web' . $src;
         //真实的图片路径
         $img_r = imagecreatefromjpeg($src);
         $ext = $path . time() . ".jpg";
         //生成的引用路径
         $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
         imagecopyresampled($dst_r, $img_r, 0, 0, Yii::$app->request->post('x'), Yii::$app->request->post('y'), $targ_w, $targ_h, Yii::$app->request->post('w'), Yii::$app->request->post('h'));
         $img = Yii::$app->basePath . '/web/' . $ext;
         //真实的图片路径
         if (imagejpeg($dst_r, $img, $jpeg_quality)) {
             //更新用户头像
             $user = YiiUser::findOne(Yii::$app->user->getId());
             $user->thumb = $ext;
             $user->save();
             $arr['status'] = 1;
             $arr['data'] = $ext;
             $arr['info'] = '裁剪成功!';
             echo json_encode($arr);
         } else {
             $arr['status'] = 0;
             echo json_encode($arr);
         }
         exit;
     }
 }