示例#1
0
 public function create()
 {
     if (!$this->auth->check()) {
         $this->app->flash("info", "You must be logged on to create a post");
         $this->app->redirect("/login");
     } else {
         if ($_POST['csrf_token'] !== $_SESSION['csrf_token']) {
             $this->app->flash("info", "Something went wrong. Please reload the page and try again.");
             $this->app->redirect("/posts/new");
         }
         $request = $this->app->request;
         $title = $request->post('title');
         $content = $request->post('content');
         $author = $_SESSION['user'];
         $date = date("dmY");
         $validation = new PostValidation($author, $title, $content);
         if ($validation->isGoodToGo()) {
             $currentUser = $this->auth->user();
             if ($this->userRepository->getIsPaying($author) == 1) {
                 //Pay $3 for doctorvisibility
                 $this->userRepository->saveSpendings($currentUser, 3);
             }
             $post = new Post();
             $post->setAuthor($author);
             $post->setTitle($title);
             $post->setContent($content);
             $post->setDate($date);
             $post->setDoctor(0);
             $savedPost = $this->postRepository->save($post);
             $this->app->redirect('/posts/' . $savedPost . '?msg=Post successfully posted');
         } else {
             $this->app->flashNow('error', join('<br>', $validation->getValidationErrors()));
             $this->app->render('createpost.twig');
         }
     }
 }
示例#2
0
 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 {
         $request = $this->app->request;
         $title = $request->post('title');
         $content = $request->post('content');
         $author = $_SESSION['user'];
         $date = date("dmY");
         $paydoc = $request->post('paydoc');
         $price = -10;
         $validation = new PostValidation($title, $author, $content, $paydoc);
         if ($validation->isGoodToGo()) {
             $post = new Post();
             $post->setAuthor($author);
             $post->setTitle($title);
             $post->setContent($content);
             $post->setDate($date);
             $post->setPayDoc($paydoc);
             if ($paydoc != 0) {
                 $this->userRepository->updateBalance($author, $price);
             }
             $savedPost = $this->postRepository->save($post);
             $this->app->redirect('/posts/' . $savedPost . '?msg="Post succesfully posted');
         }
     }
     $this->app->flashNow('error', join('<br>', $validation->getValidationErrors()));
     $this->app->render('createpost.twig');
 }
示例#3
0
 public function create()
 {
     if ($this->auth->guest()) {
         $this->app->flash("info", "You must be logged in to create a post");
         $this->app->redirect("/login");
     } else {
         $request = $this->app->request;
         $title = $request->post('title');
         $content = $request->post('content');
         $token = $request->post('csrf_token');
         $payed = $request->post('ispayedpost');
         $author = $this->auth->user()->getUsername();
         // Username of logged in user
         $date = date("dmY");
         $missingBankAccountWhenNeeded = $payed == '1' && $this->auth->user()->getBankcard() == '';
         $validation = new PostValidation($title, $author, $content, $token, $missingBankAccountWhenNeeded);
         if ($validation->isGoodToGo()) {
             $post = new Post();
             $post->setAuthor($author);
             $post->setTitle($title);
             $post->setContent($content);
             $post->setDate($date);
             $post->setIsPayedPost($payed);
             $savedPost = $this->postRepository->save($post);
             $this->app->redirect('/posts/' . $savedPost . '?msg=Post succesfully posted');
         }
     }
     $this->app->flash('error', join('<br>', $validation->getValidationErrors()));
     $this->app->redirect('/posts/new');
     // RENDER HERE
 }
示例#4
0
 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]);
 }