public function handleForm(Context $context, $action)
 {
     if ($action == "client") {
         if ($_POST['name'] != "" && $_POST['username'] != "" && $_POST['password'] != "" && $_POST['repeatpassword'] != "" && $_POST['email'] != "" && $_POST['phone'] != "" && $_POST['address'] != "") {
             if ($_POST['password'] == $_POST['repeatpassword']) {
                 if (LoginDao::usernameFree($_POST['username'])) {
                     $newLogin = LoginDao::createLogin($_POST['username'], $_POST['password'], Login::CLIENT);
                     $newClient = ClientDao::createClient($newLogin, $_POST['name'], $_POST['email'], $_POST['phone'], $_POST['address']);
                     SessionUtil::login($newLogin);
                     $context->setPageID("home");
                 } else {
                     $context->addError("Username already taken.");
                 }
             } else {
                 $context->addError("Passwords don't match.");
             }
         } else {
             $context->addError("Required field left blank.");
         }
     } else {
         $context->addError("Incorrect Action.");
     }
 }
Example #2
0
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once './Config.php';
require_once './lib/DB/Database.php';
require_once './lib/Site/Page.php';
require_once './lib/Site/StandardLayout.php';
require_once './lib/Site/StandardNavigation.php';
require_once './lib/Util/Context.php';
require_once './lib/Util/SessionUtil.php';
if (!SessionUtil::start()) {
    echo "Error Starting Session";
}
Database::Open();
$context = new Context();
$context->setPageID("home");
if (isset($_GET['pageid'])) {
    $context->setPageID($_GET['pageid']);
} else {
    if (isset($_POST['pageid'])) {
        $context->setPageID($_POST['pageid']);
    }
}
if (isset($_POST['action'])) {
    $action = $_POST['action'];
    if ($context->getPageID() == "login") {
        require_once './lib/Form/LoginHandler.php';
        $loginHandler = new LoginHandler();
        $loginHandler->handleForm($context, $action);
    } else {
        if ($context->getPageID() == "register") {