Пример #1
0
 public function getLoginPage(Request $request, Session $session)
 {
     if ($session->userIsLoggedIn()) {
         return $this->redirectTo('/dashboard');
     }
     $view = new View('login');
     return $view->render();
 }
Пример #2
0
 public function getFeedbackForm(Request $request, Session $session, $auction_id)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     $auction = Auction::getAuctionWithId($auction_id);
     return View::renderView('feedback_form', ['auction' => $auction]);
 }
Пример #3
0
 public function getDashboard(Request $request, Session $session)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     if ($session->activeUser()->isSeller()) {
         $liveSellerAuctions = Auction::getLiveAuctionsForUser($session->activeUser()->sellerID());
         $completedSellerAuctions = Auction::getCompletedAuctionsForUser($session->activeUser()->sellerID());
         $sellerFeedback = $session->activeUser()->getSellerFeedback();
         $sellerRating = $session->activeUser()->getSellerMeanRating();
     }
     if ($session->activeUser()->isBuyer()) {
         $liveBidBuyerAuctions = Auction::getLiveBidAuctionsForUser($session->activeUser()->buyerID());
         $completedBidBuyerAuctions = Auction::getCompletedBidAuctionsForUser($session->activeUser()->buyerID());
         $liveWatchedBuyerAuctions = Auction::getLiveWatchedAuctionsForUser($session->activeUser()->buyerID());
         $buyerFeedback = $session->activeUser()->getBuyerFeedback();
         $buyerRating = $session->activeUser()->getBuyerMeanRating();
         $recommendations = $session->activeUser()->getRecommendations();
     }
     $view = new View('dashboard', ['liveSellerAuctions' => isset($liveSellerAuctions) ? $liveSellerAuctions : NULL, 'completedSellerAuctions' => isset($completedSellerAuctions) ? $completedSellerAuctions : NULL, 'sellerFeedback' => isset($sellerFeedback) ? $sellerFeedback : NULL, 'sellerRating' => isset($sellerRating) ? $sellerRating : NULL, 'liveBidBuyerAuctions' => isset($liveBidBuyerAuctions) ? $liveBidBuyerAuctions : NULL, 'completedBidBuyerAuctions' => isset($completedBidBuyerAuctions) ? $completedBidBuyerAuctions : NULL, 'liveWatchedBuyerAuctions' => isset($liveWatchedBuyerAuctions) ? $liveWatchedBuyerAuctions : NULL, 'buyerFeedback' => isset($buyerFeedback) ? $buyerFeedback : NULL, 'buyerRating' => isset($buyerRating) ? $buyerRating : NULL, 'recommendations' => isset($recommendations) ? $recommendations : NULL, 'message' => isset($request->get['message']) ? $request->get['message'] : NULL, 'error' => isset($request->get['error']) ? $request->get['error'] : NULL]);
     return $view->render();
 }
Пример #4
0
 public function processSignup(Request $request, Session $session)
 {
     if ($session->userIsLoggedIn()) {
         return $this->redirectTo('/dashboard');
     }
     if (isset($request->post['email']) && isset($request->post['password']) && (isset($request->post['buyer_account']) || isset($request->post['seller_account'])) && ($request->post['buyer_account'] == 1 || $request->post['seller_account'] == 1)) {
         if (Database::checkExists($request->post['email'], 'email', 'User')) {
             return View::renderView('login', ['signup_errors' => 'Email already exists']);
         }
         Database::insert('INSERT INTO User (email,password) VALUES (?,?)', [$request->post['email'], password_hash($request->post['password'], PASSWORD_DEFAULT)]);
         $user_id = Database::lastID();
         if ($request->post['buyer_account'] == 1) {
             Database::insert('INSERT INTO UserRole (user_id, role_id) VALUES (?,?)', [$user_id, Role::buyer()]);
         }
         if ($request->post['seller_account'] == 1) {
             Database::insert('INSERT INTO UserRole (user_id, role_id) VALUES (?,?)', [$user_id, Role::seller()]);
         }
         $session->generateSession($user_id);
         return $this->redirectTo('/dashboard');
     }
     return View::renderView('login', ['signup_errors' => 'You must complete the signup form']);
 }
Пример #5
0
 public function createNewAuction(Request $request, Session $session)
 {
     if (!$session->userIsLoggedIn()) {
         return $this->redirectTo('/login');
     }
     if (!$session->activeUser()->isSeller()) {
         return $this->redirectTo('/dashboard?error=' . urlencode('You must register as a seller to create an auction'));
     }
     $auction_input = $request->post;
     $auction_input['userrole_id'] = $session->activeUser()->sellerID();
     $auction_creator = new AuctionCreator($request);
     $auction_errors = $auction_creator->validateInput($auction_input);
     $errors = [];
     if (count($auction_errors) > 0) {
         $errors[] = 'There was one or more problems with your submission, please go back';
         foreach ($auction_errors as $error) {
             $errors[] = $error;
         }
     }
     if (isset($auction_input['items']) === false) {
         $auction_errors[] = 'Items Missing';
     }
     if (isset($request->files['item_image']['name']) === false || count($request->files['item_image']['name']) !== count($auction_input['items'])) {
         $auction_errors[] = 'Items Images Missing';
     }
     $items = $this->processInput($auction_input['items'], $request->files['item_image']);
     $item_creator = new ItemCreator($request);
     foreach ($items as $key => $item) {
         $item_errors = $item_creator->validateInput($item);
         if (count($item_errors) > 0) {
             foreach ($item_errors as $error) {
                 $errors[] = $error;
             }
         }
     }
     if (count($errors)) {
         return View::renderView('general_error', ['errors' => $errors]);
     }
     $auction_id = $auction_creator->saveInput($auction_input);
     foreach ($items as $key => $item) {
         $item['auction_id'] = $auction_id;
         $item_id = $item_creator->saveInput($item);
     }
     return $this->redirectTo('/dashboard?message=' . urlencode('Auction Created'));
 }
Пример #6
0
 public function handleRequest(Request $request)
 {
     $session = new Session($request);
     View::$current_user = $session->activeUser();
     NotificationSender::scanForItemWonNotifications();
     NotificationSender::scanForItemEndedNotifications();
     if ($request->matches('GET', '/test')) {
         $controller = new TestController();
         return $controller->runTest($request, $session);
     } else {
         if ($request->matches('GET', '/dashboard')) {
             $controller = new DashboardController();
             return $controller->getDashboard($request, $session);
         } else {
             if ($request->matches('GET', '/login')) {
                 $controller = new LoginController();
                 return $controller->getLoginPage($request, $session);
             } else {
                 if ($request->matches('POST', '/login')) {
                     $controller = new LoginController();
                     return $controller->processLoginAttempt($request, $session);
                 } else {
                     if ($request->matches('POST', '/signup')) {
                         $controller = new SignupController();
                         return $controller->processSignup($request, $session);
                     } else {
                         if ($request->matches('GET', '/logout')) {
                             $controller = new LoginController();
                             return $controller->logout($request, $session);
                         } else {
                             if ($request->matches('GET', '/auction/create')) {
                                 $controller = new AuctionController();
                                 return $controller->getCreateAuctionPage($request, $session);
                             } else {
                                 if ($request->matches('GET', '/auction/??/edit')) {
                                     return "You are at /auction/id/edit";
                                     //just a dumb placeholder for sanity check
                                 } else {
                                     if ($request->matches('POST', '/auction')) {
                                         $controller = new AuctionController();
                                         return $controller->createNewAuction($request, $session);
                                     } else {
                                         if ($request->matches('GET', '/auction/??')) {
                                             $controller = new AuctionController();
                                             return $controller->getAuction($request, $session);
                                         } else {
                                             if ($request->matches('POST', '/auction/??/bid')) {
                                                 $controller = new AuctionController();
                                                 return $controller->getBidConfirmationPage($request, $session);
                                             } else {
                                                 if ($request->matches('POST', '/auction/??/watch')) {
                                                     $controller = new AuctionController();
                                                     return $controller->getWatchConfirmationPage($request, $session);
                                                 } else {
                                                     if ($request->matches('GET', '/auction/??/feedback/create')) {
                                                         $controller = new FeedbackController();
                                                         return $controller->getFeedbackForm($request, $session, (int) $request->url_array[1]);
                                                     } else {
                                                         if ($request->matches('POST', '/auction/??/feedback/buyer')) {
                                                             $controller = new FeedbackController();
                                                             return $controller->postBuyerFeedback($request, $session, (int) $request->url_array[1]);
                                                         } else {
                                                             if ($request->matches('POST', '/auction/??/feedback/seller')) {
                                                                 $controller = new FeedbackController();
                                                                 return $controller->postSellerFeedback($request, $session, (int) $request->url_array[1]);
                                                             } else {
                                                                 if ($request->matches('GET', '/user/??/feedback')) {
                                                                     $controller = new FeedbackController();
                                                                     return $controller->getFeedbackList($request, $session, (int) $request->url_array[1]);
                                                                 } else {
                                                                     if ($request->matches('GET', '/search')) {
                                                                         $controller = new SearchController();
                                                                         return $controller->getSearch($request, $session);
                                                                     } else {
                                                                         if ($request->matches('GET', '/')) {
                                                                             $controller = new HomeController();
                                                                             return $controller->getHomepage($request, $session);
                                                                         } else {
                                                                             if ($request->matches('GET', '/notifications/clear')) {
                                                                                 $controller = new NotificationController();
                                                                                 return $controller->clearNotifications($request, $session);
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return View::renderView('general_error', ['user' => $session->activeUser(), 'message' => 'URL Not Found']);
 }