Example #1
0
         $acct->login();
     } else {
         if ($_POST['form'] === 'register') {
             //Form Validation
             if ($form->validateAddUser()) {
                 //If validation passes, add the user to the database.
                 $user = new GameMania\Model\User(0, $_POST['username'], $_POST['email'], hash("sha256", $_POST['password']));
                 //If the user is successfully registered, tell them.
                 if ($userMapper->addUser($user)) {
                     $msg = "Successfully registered the user!";
                 }
             }
         } else {
             if ($_POST['form'] === 'addProduct') {
                 //Form Validation
                 if ($form->validateAddGame()) {
                     //If validation passes, add the game to the database.
                     $game = new GameMania\Model\Game(0, $_POST['title'], $_POST['developer'], $_POST['console'], $_POST['price'], $_POST['rating'], $_POST['comments']);
                     //If the game is successfully added, tell the user.
                     if ($gameMapper->addGame($game)) {
                         $msg = "Successfully added the game!";
                     }
                 }
             } else {
                 throw new \Exception("Invalid form. Please fill out an appropriate form.");
             }
         }
     }
 } catch (\Exception $e) {
     $msg = $e->getMessage();
 }