예제 #1
0
 /**
  * Загружает резюме по идентификатору и токену
  * @param int $id
  * @return \app\models\cv\Cv
  */
 protected function loadCv($id, $token)
 {
     $cv = Cv::find()->byId($id)->withRelated()->active()->one();
     //задаем язык сайта на основе языка резюме
     if ($cv->language) {
         Yii::$app->language = $cv->language;
     }
     if (!$cv) {
         throw new NotFoundHttpException('Запись не найдена');
     }
     //проверяем права на доступ к резюме
     if (Yii::$app->user->isGuest || !Yii::$app->user->can('*/*/*') && !Yii::$app->user->can('cv/*') && !Yii::$app->user->can('cv/index')) {
         //пробуем проверить токен
         //ищем юзера по его токену
         $user = User::find()->byCvToken($token)->one();
         if (!$user) {
             throw new NotFoundHttpException('Запись не найдена');
         }
         //перебираем все разрешенные юзеру резюме, чтобы найти заданное
         $canAccess = false;
         foreach ($user->cv as $allowed) {
             if ($allowed->id !== $cv->id) {
                 continue;
             }
             $canAccess = true;
             break;
         }
         if (!$canAccess) {
             throw new NotFoundHttpException('Запись не найдена');
         }
         //отмечаем посещение для неавторизованного пользователя
         $user->visitCv($cv);
     }
     return $cv;
 }
예제 #2
0
 public function rules()
 {
     return [[['email', 'password'], 'required'], ['email', 'email'], ['email', function () {
         $this->user = User::find()->where(['email' => $this->email])->one();
         if (!$this->user || !$this->user->validatePassword($this->password)) {
             $this->addError('password', 'Email or Password incorrect.');
         }
     }, 'when' => function () {
         return (bool) $this->email && $this->password;
     }]];
 }
예제 #3
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user = User::find()->where(['email' => $this->email])->one();
     if ($this->user) {
         $model = new Reset();
         $model->user_id = $this->user->id;
         return $model->save();
     }
     return true;
 }
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $user = User::find($id);
     if ($user) {
         if ($user->delete()) {
             return response()->json(true);
         }
     }
     return response()->json('userul nu s-a putut sterge', 500);
 }
예제 #5
0
 /**
  * @验证手机号唯一
  */
 public function onlyPhone($phone)
 {
     $res = User::find()->select(['user_id'])->where(['user_phone' => $phone])->asArray()->one();
     return $res['user_id'];
 }
예제 #6
0
 public function postFaceUpload(Request $request)
 {
     $content = $request->getContent();
     $requestUri = $request->getRequestUri();
     $authorization = @base64_decode($request->server('HTTP_AUTHORIZATION'));
     $ossPubKeyUrl = @base64_decode($request->server('HTTP_X_OSS_PUB_KEY_URL'));
     $pubKey = @file_get_contents($ossPubKeyUrl);
     $pos = strpos($requestUri, '?');
     if (false === $pos) {
         $authString = urldecode($requestUri) . "\n" . $content;
     } else {
         $authString = urldecode(substr($requestUri, 0, $pos)) . substr($requestUri, $pos, strlen($requestUri) - $pos) . "\n" . $content;
     }
     if ($pubKey && openssl_verify($authString, $authorization, $pubKey, OPENSSL_ALGO_MD5)) {
         try {
             $id = decrypt($request->input('identifier'));
             $user = User::find($id);
             $config = config('aliyun.oss.archimore');
             $oss = new OssClient($config['access_key_id'], $config['access_key_secret'], $config['endpoint'], $config['is_cname'], $config['security_token']);
             $user->face && $oss->deleteObject('archimore', $user->face);
             $user->face = $request->input('object');
             $user->save();
             $data = ['status' => true, 'message' => '头像设置成功', 'face' => $config['image_base_url'] . $request->input('object') . $config['image_style_separator'] . 'face-middle'];
         } catch (\Exception $e) {
             $data = ['status' => false, 'message' => '头像设置失败'];
         }
     } else {
         $data = ['status' => false, 'message' => '头像上传失败'];
     }
     $data = json_encode($data);
     return response($data, 200, ['Content-Type' => 'application/json', 'Content-Length' => strlen($data)]);
 }
예제 #7
0
 public function postFileList($id, Request $request)
 {
     $this->projectId = $id = (int) $id;
     if (!$this->getProjectPermission('view-project')) {
         return response()->json(['status' => false, 'message' => '没有权限查看文件信息']);
     }
     $project = $this->getProject();
     $dirId = (int) $request->input('dirId');
     $root = new ProjectFile();
     $root->id = 0;
     $root->is_dir = 1;
     $root->user_id = 0;
     $root->project_id = $id;
     $root->parent_id = 0;
     $root->name = '根目录';
     $root->type = 'default_dir';
     $root->path = '/';
     $root->created_at = $project->created_at;
     $root->updated_at = $project->created_at;
     if ($dirId > 0) {
         $parent = ProjectFile::where('id', $dirId)->where('project_id', $id)->where('is_dir', 1)->first();
         if (!$parent) {
             return response()->json(['status' => false, 'message' => '你查看的目录不存在']);
         }
         $parent->current = true;
     } else {
         $parent = $root;
     }
     $requestDirId = $dirId = $parent->id;
     $list = ProjectFile::where('project_id', $id)->where('parent_id', $dirId)->orderBy('user_id', 'asc')->orderBy('is_dir', 'desc')->orderBy('id', 'asc')->get();
     if ($parent->id > 0) {
         $idList = explode('/', trim($parent->path, '/'));
         array_pop($idList);
         if ($idList) {
             $paths = ProjectFile::whereIn('id', $idList)->where('project_id', $id)->where('is_dir', 1)->get();
             $paths->push($parent);
         } else {
             $paths = collect([$parent]);
         }
         $paths->sortBy(function ($dir) use($parent, $list) {
             if ($parent->parent_id == $dir->id) {
                 $dir->type = 'back_dir';
                 $list->prepend($dir);
             }
             return substr_count($dir->path, '/');
         });
         if ($parent->parent_id == 0) {
             $root->type = 'back_dir';
             $list->prepend($root);
         }
     } else {
         $paths = collect();
     }
     $members = $project->members->keyBy('user_id');
     $users = [];
     $dirIcon = asset('assets/archimore/img/folder.png');
     $fileIcon = asset('assets/archimore/img/file.png');
     foreach ($list as $file) {
         if ($file->is_dir) {
             $file->icon = $dirIcon;
         } else {
             if ($file->type == 'file') {
                 $file->icon = $fileIcon;
             } else {
                 if ($file->type == 'image') {
                     $file->icon = oss_image_url($file->url, '120x120');
                 }
             }
         }
         if (!$file->is_dir) {
             if ($file->format) {
                 $file->edit_name = (string) substr($file->name, 0, strrpos($file->name, '.'));
             } else {
                 $file->edit_name = $file->name;
             }
             $file->download_url = $file->getLink();
             if ($file->type == 'image') {
                 $file->open_url = url('project/image/' . $id . '-' . $file->id);
             }
         }
         $file->name = e($file->name);
         $file->create_time = $file->created_at->toDateTimeString();
         $file->update_time = $file->updated_at->toDateTimeString();
         if ($file->user_id == 0) {
             $file->user_name = '系统创建';
         } else {
             if (isset($members[$file->user_id])) {
                 $file->user_name = $members[$file->user_id]->user_name;
             } else {
                 if (!isset($users[$file->user_id])) {
                     $user = User::find($file->user_id);
                     $users[$file->user_id] = $user ? $user->realname : '未知';
                 }
                 $file->user_name = $users[$file->user_id];
             }
         }
     }
     return response()->json(['status' => true, 'message' => '', 'data' => $list->toArray(), 'path' => $paths->toArray()]);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $order = Order::find($id);
     $client = User::find($order->client_id);
     $products = OrderEntry::where('order_id', $order->id)->get();
     $managers = User::where('role_id', '2')->lists('name', 'id');
     return view('orders.edit', ['order' => $order, 'managers' => $managers, 'client' => $client, 'products' => $products]);
 }
예제 #9
0
 /**
  * Список
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => User::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }