コード例 #1
0
ファイル: PostController.php プロジェクト: johannsl/progsec
 public function create()
 {
     if ($this->auth->guest()) {
         $this->app->flash("info", "You must be logged on to create a post");
         $this->app->redirect("/login");
     } else {
         if ($this->userRepository->findByUser($_SESSION['user'])->isDoctor() == true) {
             $this->app->flash("info", "Doctors cannot create posts");
             $this->app->redirect("/posts");
         } else {
             $request = $this->app->request;
             $title = $request->post('title');
             $content = $request->post('content');
             $pay = $request->post('pay');
             $author = $_SESSION['user'];
             $date = date("dmY");
             $validation = new PostValidation($author, $title, $content, $request->post('csrftoken'));
             if ($validation->isGoodToGo()) {
                 $post = new Post();
                 $post->setAuthor($author);
                 $post->setTitle($title);
                 $post->setContent($content);
                 $post->setDate($date);
                 $post->setPay($pay);
                 $savedPost = $this->postRepository->save($post);
                 $this->app->flash('info', 'Post succesfully posted');
                 $this->app->redirect('/posts/' . $savedPost);
             }
         }
     }
     // Does this ever occur?
     $this->app->flashNow('error', join("\n", $validation->getValidationErrors()));
     $username = $_SESSION['user'];
     $user = $this->userRepository->findByUser($username);
     $this->render('createpost.twig', ['user' => $user]);
 }