/** * @param ServerRequestInterface $request * @return ResponseInterface */ public function update(ServerRequestInterface $request) { $validator = new Validator(['name' => [Validator::required(), Validator::length(2, 20)]]); if (!$validator->validate($request->getParsedBody())) { return Response::factory(400, $validator->getErrorMessage()); } $id = $request->getAttribute('id'); $name = Input::fromBody('name'); $this->repository->where(compact('id'))->update(compact('name')); return Response::redirect('/admin/settings/categories'); }
/** * @param ServerRequestInterface $request * @return ResponseInterface */ public function update(ServerRequestInterface $request) { $validator = new Validator(['title' => [Validator::required(), Validator::length(1, 100)], 'category' => [Validator::required()]]); if (!$validator->validate($request->getParsedBody())) { return Response::factory(400, $validator->getErrorMessage()); } $title = Input::fromBody('title'); $category = Input::fromBody('category'); $contents = Input::fromBody('contents'); $url = Input::fromBody('url'); $link = Input::fromBody('link'); $filter = Input::fromBody('filter'); $facebook = Input::fromBody('facebook'); $master = Input::fromBody('master'); $address = Input::fromBody('address'); $phone = Input::fromBody('phone'); $time = Input::fromBody('time'); $seat = Input::fromBody('seat'); $parking = Input::fromBody('parking'); $lat = Input::fromBody('lat'); $lng = Input::fromBody('lng'); $event = Input::fromBody('event'); $eventTitle = Input::fromBody('eventTitle'); $eventContents = Input::fromBody('eventContents'); $eventLink = Input::fromBody('eventLink'); $valuesToUpdate = ['title' => $title, 'category_id' => $category, 'contents' => $contents, 'extra' => ['url' => $url, 'link' => $link, 'store' => ['filter' => $filter, 'facebook' => $facebook, 'master' => $master, 'address' => $address, 'phone' => $phone, 'time' => $time, 'seat' => $seat, 'parking' => $parking, 'lat' => $lat, 'lng' => $lng, 'event' => $event], 'event' => ['eventTitle' => $eventTitle, 'eventContents' => $eventContents, 'eventLink' => $eventLink]]]; $files = $request->getUploadedFiles(); $post = $this->repository->get($request->getAttribute('id')); $valuesToUpdate['thumbnail'] = $this->fileParser($files['thumbnail']); if (!isset($valuesToUpdate['thumbnail'])) { $valuesToUpdate['thumbnail'] = isset($post['thumbnail']) ? $post['thumbnail'] : ''; if (Input::fromBody('thumbnailDelete') === '1') { $valuesToUpdate['thumbnail'] = ''; } } for ($i = 0; $i < 4; $i++) { $file = $this->fileParser($files['eventImage' . $i]); if (isset($file)) { $valuesToUpdate['extra']['event']['eventImage'][$i] = $file; } else { $valuesToUpdate['extra']['event']['eventImage'][$i] = isset($post['extra']['event']['eventImage'][$i]) ? $post['extra']['event']['eventImage'][$i] : ''; if (Input::fromBody('eventImageDelete' . $i) === '1') { $valuesToUpdate['extra']['event']['eventImage'][$i] = ''; } } } $this->repository->where(['id' => $request->getAttribute('id')])->update($valuesToUpdate); return Response::redirect('/admin/posts'); }
/** * @param ServerRequestInterface $request * @return ResponseInterface */ public function login(ServerRequestInterface $request) { $input = $request->getParsedBody(); $token = $input['_token']; $username = $input['username']; $password = $input['password']; $csrf = new Csrf(); if (!$csrf->isInSafety($token)) { return Response::factory(400, 'Not Accepted Request; Wrong token.'); } Session::remove('csrf_token'); $user = $this->repository->where(['username' => $username, 'password' => $password])->one(); if (!isset($user) || $user['level'] > 0) { return Response::factory(400, 'Not Accepted Request; Wrong username or password.'); } Session::set('isLogin', true); Session::set('username', $username); return Response::back($request); }