コード例 #1
0
ファイル: ControllerApi.php プロジェクト: smilexx/taskgame
 protected function checkAuthAdmin()
 {
     if (!Auth::checkAdmin()) {
         throw new \App\Exceptions\ExceptionApiAuthRequire($this->_request_params, $this->_typeName, $this->_methodName);
     }
     return true;
 }
コード例 #2
0
 public function edit()
 {
     $this->_methodName = 'edit';
     $this->resolveParams();
     if ($this->checkAuth() && !Auth::checkAdmin()) {
         throw new \App\Exceptions\ExceptionApiMethodbad($this->_typeName, $this->_methodName, $this->_request_params);
     }
     $arNeed = ['taskId' => 'required|numeric'];
     $this->checkAttr($arNeed);
     $this->checkAuth();
     $task = \App\Task::whereId($this->_request_params['taskId'])->first();
     if (is_null($task)) {
         throw new \App\Exceptions\ExceptionApiContactnotfound($this->_request_params, $this->_typeName, $this->_methodName);
     }
     if (isset($this->_request_params['name'])) {
         $arNeed = ['name' => 'required'];
         $this->checkAttr($arNeed);
         $task->name = trim($this->_request_params['name']);
     }
     if (isset($this->_request_params['description'])) {
         $arNeed = ['description' => 'required'];
         $this->checkAttr($arNeed);
         $task->description = trim($this->_request_params['description']);
     }
     if (isset($this->_request_params['score'])) {
         $arNeed = ['score' => 'required|numeric'];
         $this->checkAttr($arNeed);
         $task->point = $this->_request_params['score'];
     }
     if (isset($this->_request_params['timer'])) {
         $arNeed = ['timer' => 'required'];
         $this->checkAttr($arNeed);
         $task->timer = $this->_request_params['timer'];
     }
     $task->save();
     return $this;
 }
コード例 #3
0
ファイル: routes.php プロジェクト: smilexx/taskgame
});
Route::get('/user/{id}', function ($id) {
    Auth::login();
    if (Auth::checkAdmin()) {
        if ((int) $id == 0) {
            return redirect('/users');
        }
        $controller = new \App\Http\Controllers\ControllerUser($id);
        return $controller->init();
    } else {
        return redirect('/');
    }
});
Route::get('/setting', function () {
    Auth::login();
    if (Auth::checkAdmin()) {
        $controller = new \App\Http\Controllers\ControllerSetting();
        return $controller->init();
    } else {
        return redirect('/');
    }
});
Route::any('/api/{model?}.{method?}', function ($model = null, $method = null) {
    $controller = 'App\\Http\\Controllers\\Api\\ControllerApi' . ucfirst($model);
    try {
        App\Services\Auth::login();
        if (class_exists($controller)) {
            if (!method_exists($controller, $method)) {
                throw new \App\Exceptions\ExceptionApiMethodbad($model, $method, Request::all());
            }
            $ob = new $controller();
コード例 #4
0
 public function changePassword()
 {
     $this->_methodName = 'edit';
     $this->resolveParams();
     // TODO Сделать изменения для админов
     $this->checkAuth();
     if (!Auth::checkAdmin()) {
         $user = Auth::user();
         $arNeed = ['oldpasswd' => 'required|min:8|max:32', 'newpasswd' => 'required|min:8|max:32'];
         $this->checkAttr($arNeed);
         if (Hash::check($this->_request_params['oldpasswd'], $user->password)) {
             $user->password = Hash::make(strip_tags(trim($this->_request_params['newpasswd'])));
             $user->save();
             return $this;
         } else {
             throw new \App\Exceptions\ExceptionApiAuthCodeinactive(['token' => $this->_request_params['token']], $this->_typeName, $this->_methodName);
         }
     } else {
         return $this;
     }
 }