diff --git a/.htaccess b/.htaccess index 4cd7a263c248496c4e068f43941b868fbe498c05..dd76ffcc45bdd5b1135abd6d3bf93dcdbe44e554 100644 --- a/.htaccess +++ b/.htaccess @@ -1,5 +1,16 @@ -Options -MultiViews +<IfModule mod_rewrite.c> +Redirect 301 / https://google.com +<IfModule mod_negotiation.c> + Options -MultiViews +</IfModule> + RewriteEngine On + +# Redirect Trailing Slashes... +RewriteRule ^(.*)/$ /$1 [L,R=301] + +# Handle Front Controller... +RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_URI} !=/img/ic_edit.jpg -RewriteRule ^ public/index.php [QSA,L] \ No newline at end of file +RewriteRule ^ index.php [L] +</IfModule> \ No newline at end of file diff --git a/public/order.js b/public/order.js index 4f0b517aa3d9b3fb9296c5850e26bdc52265d36e..955b590549c1df16c3954125fd6c737f9e0c664b 100755 --- a/public/order.js +++ b/public/order.js @@ -14,7 +14,7 @@ function makeOrder() { var data = "id="+customerID+"&pickup="+orderPickup+"&destination="+orderDestination+"&driver="+orderPreferredDriver; if (orderPickup.trim() == "" || orderDestination.trim() == "") { - alert("Sorce and destination is required!"); + alert("Source and destination is required!"); return; } @@ -31,7 +31,7 @@ function makeOrder() { } }; - xhttp.open("POST", "/main/order/new", true); + xhttp.open("POST", "/index.php/main/order/new", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(data); } @@ -144,11 +144,11 @@ function completeOrder(id) { alert("Fail completing your order"); } else { alert("Thanks for your order :D"); - window.location.href = "/main/order?u="+customerID; + window.location.href = "/index.php/main/order?u="+customerID; } } }; - xhttp.open("POST", "/main/order/finish?u", true); + xhttp.open("POST", "/index.php/main/order/finish?u", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(data); diff --git a/public/profil_edit.js b/public/profil_edit.js index 66c774a3ceb0d9c6bb9bc459db370a18031da2df..f9af165ecf23232652d735cb121c38c5775f8905 100644 --- a/public/profil_edit.js +++ b/public/profil_edit.js @@ -83,13 +83,13 @@ function saveLocation(location, newlocation) { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (this.responseText == "Success") { - window.location.href = "/main/profil/location/edit?u="+id; + window.location.href = "/index.php/main/profil/location/edit?u="+id; } else { alert(this.responseText); } } }; - xhttp.open("POST", "/main/profil/location/edit/data", true); + xhttp.open("POST", "/index.php/main/profil/location/edit/data", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(data); } \ No newline at end of file diff --git a/public/scripts.js b/public/scripts.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..679aa31046f5c72c82c9276a4a85b37cd6bbdf6b 100755 --- a/public/scripts.js +++ b/public/scripts.js @@ -0,0 +1,103 @@ +function checkAvailability(string, elmtID, dataCollection) { + var field = document.getElementById(elmtID); + + if (string.length === 0) { + field.classList.remove("available"); + field.classList.remove("unavailable"); + return; + } else { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + if (this.responseText === "available") { + field.classList.remove("unavailable"); + field.classList.add("available"); + } else { + field.classList.remove("available"); + field.classList.add("unavailable"); + } + } + }; + xmlhttp.open("GET", dataCollection + "?q=" + string, true); + xmlhttp.send(); + } +} + +function checkRequiredField(elmtID) { + var field = document.getElementById(elmtID); + + if (field.value === "") { + field.classList.add("empty-required"); + return false; + } else { + field.classList.remove("empty-required"); + return true; + } +} + +var isNameFilled = false; +var isUsernameFilled = false; +var isPasswordFilled = false; +var isEmailFilled = false; +var isPhoneFilled = false; +var isPasswordMatch = false; +var isUsernameAvailable = false; +var isEmailAvailable = false; + + +document.getElementById("confirm-password").onkeyup = function () { + var confirmField = document.getElementById("confirm-password"); + var passwordField = document.getElementById("password"); + + if (confirmField.value !== passwordField.value) { + confirmField.classList.add("not-match"); + passwordField.classList.add("not-match"); + isPasswordMatch = false; + } else { + confirmField.classList.remove("not-match"); + passwordField.classList.remove("not-match"); + isPasswordMatch = true; + } +}; + + +document.getElementById("name").onkeyup = function () { + isNameFilled = checkRequiredField("name"); +}; + +document.getElementById("username").onkeyup = function () { + isUsernameFilled = checkRequiredField("username"); + checkAvailability(this.value, "username", '/index.php/register/validate/username'); + isUsernameAvailable = this.classList.contains("available"); +}; + +document.getElementById("password").onkeyup = function () { + isPasswordFilled = checkRequiredField("password"); +}; + +document.getElementById("email").onkeyup = function () { + isEmailFilled = checkRequiredField("email"); + checkAvailability(this.value, "email", '/index.php/register/validate/email'); + isEmailAvailable = this.classList.contains("available"); +}; + +document.getElementById("phone").onkeyup = function () { + isPhoneFilled = checkRequiredField("phone"); +}; + +document.getElementById("register-form").onkeyup = function () { + var submitBtn = document.getElementById("sign-up-btn"); + + if (isNameFilled && + isUsernameFilled && + isPasswordFilled && + isEmailFilled && + isPhoneFilled && + isPasswordMatch && + isUsernameAvailable && + isEmailAvailable) { + submitBtn.removeAttribute("disabled"); + } else { + submitBtn.setAttribute("disabled", "true"); + } +}; \ No newline at end of file diff --git a/public/style.css b/public/style.css index 9ab45e6ec603423392c3987cb56bcb100bb362dc..79bbb4b5a509c9c91cd56653985babf5ce21b7ba 100755 --- a/public/style.css +++ b/public/style.css @@ -410,3 +410,41 @@ input:checked + .slider:before { flex-direction: column; justify-content: center; } + +/* Login Page */ + +.login-input { + margin: 5px 0 5px 0; +} + +.login-link { + float: right; + margin-top: 10px; +} + +/* Register Page */ + +#sign-up-btn { + float: right; +} + +.register-link { + float: left; + margin-top: 8px; +} + +.checkbox { + margin: 10px 0 10px 0; +} + +.available { + background-color: greenyellow; +} + +.unavailable, .empty-required, .not-match { + background-color: orangered; +} + +.not-match::-webkit-input-placeholder, .empty-required::-webkit-input-placeholder, .unavailable::-webkit-input-placeholder { + color: whitesmoke; +} \ No newline at end of file diff --git a/src/app.php b/src/app.php index 86dad5f242fae056960c6bd5806d9fbdc22ead2c..8cf86b880774bf77b2f532e39e5c4d6a5166d428 100644 --- a/src/app.php +++ b/src/app.php @@ -18,7 +18,6 @@ class DagoJek { $instance = new DagoJek(); } - include_once 'model/User.php'; $instance->includeAllController(); return $instance; @@ -54,6 +53,7 @@ class DagoJek { public function Start() { $base_url = $this->getCurrentUri(); + $base_url = $this->trimIndexDotPHP($base_url); if (array_key_exists ($base_url, $this->routingTable)) { $this->routingTable[$base_url](); } else { @@ -61,5 +61,16 @@ class DagoJek { die ("404 Page not Found"); } } + + private function trimIndexDotPHP($string) { + $unnecessaryChars = "/index.php"; + + if (strpos($string, $unnecessaryChars) === 0) { + $result = substr($string, strlen($unnecessaryChars)); + return $result; + } else { + return $string; + } + } } diff --git a/src/controller/EmailValidationController.php b/src/controller/EmailValidationController.php deleted file mode 100644 index 0c6bb93a413477ce4dc2e415b7062a952bbcca53..0000000000000000000000000000000000000000 --- a/src/controller/EmailValidationController.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: iqbal - * Date: 05/10/17 - * Time: 23:14 - */ - - include_once __DIR__."/../model/User.php"; - -class EmailValidationController { - public static function EmailValidationHandler() { - $emailInput = $_REQUEST['q']; - - $pdo = DB::getInstance(); - if ($emailInput !== "") { - if (filter_var($emailInput, FILTER_VALIDATE_EMAIL)) { - if (User::GetUserBy("email", $emailInput, $pdo)) { - echo "unavailable"; - } else { - echo "available"; - } - } else { - echo "unavailable"; - } - } - } -} \ No newline at end of file diff --git a/src/controller/LoginController.php b/src/controller/LoginController.php index 0aba288cf30c561352b1992c24bb4e7c47d97c7a..6f6547534244e01ff1b36000ab0af9073999ef34 100644 --- a/src/controller/LoginController.php +++ b/src/controller/LoginController.php @@ -1,13 +1,27 @@ <?php +/** + * Created by PhpStorm. + * User: iqbal + * Date: 06/10/17 + * Time: 13:22 + */ require_once __DIR__.'/../model/User.php'; -class LoginController { - public static function LoginHandler() { +class LoginController +{ + public static function LoginHandler() + { session_start(); - $pdo = DB::getInstance(); - $userData = User::GetAllUsernameAndPassword($pdo); + $userData = null; + + if (isset($_POST['username'])) { + $username = $_POST['username']; + $password = md5($_POST['password']); + $pdo = DB::getInstance(); + $userData = User::GetUserBy('username', $username, $pdo); + } if (isset($_GET['logout'])) { $_SESSION['username'] = ""; @@ -15,15 +29,20 @@ class LoginController { exit; } - if (isset($_POST['username'])) { - if ($userData[$_POST['username']] === md5($_POST['password'])) { - $_SESSION['username'] = $_POST['username']; - //header untuk redirect - echo "<script type='application/javascript'> alert('Login berhasil'); </script>"; - header("Location: /main/profil"); + if ($userData !== null && $userData instanceof User) { + if ($userData->password === $password) { + $_SESSION['username'] = $username; + + $userPage = simpleCrypt($userData->id); + header("Location: /index.php/main/profil?u=$userPage"); + //echo "<script type='application/javascript'> alert('Login berhasil'); </script>"; } else { - echo "<script type='application/javascript'> alert('Username atau password salah'); </script>"; + echo "<script type='application/javascript'> alert('Password salah.'); </script>"; } + } else if ($userData !== null) { + echo "<script type='application/javascript'> alert('Username tidak terdaftar.'); </script>"; } + + require __DIR__ . "/../view/login.php"; } } \ No newline at end of file diff --git a/src/controller/MainController.php b/src/controller/MainController.php index d60a327df177f1b4246c01fe60869805c02c0a82..944195307c4fee5f7bffb227db59d4f262771138 100644 --- a/src/controller/MainController.php +++ b/src/controller/MainController.php @@ -3,12 +3,11 @@ class MainController { public static function LoginHandler() { - header("Location: http://dagojek.dev/src/view/login.html"); - die(); + LoginController::LoginHandler(); } public static function DefaultHandler() { - require __DIR__.'/../view/login.html'; + echo "This is default handler"; } } \ No newline at end of file diff --git a/src/controller/RegisterController.php b/src/controller/RegisterController.php index 5e6d1794ca226a6e6884916ed6e84a1aa5197b91..5b3fdfff6304a9363d3fb22562f8601dd2552f9b 100644 --- a/src/controller/RegisterController.php +++ b/src/controller/RegisterController.php @@ -1,30 +1,72 @@ <?php +/** + * Created by PhpStorm. + * User: iqbal + * Date: 07/10/17 + * Time: 0:40 + */ require_once __DIR__.'/../model/User.php'; -class RegisterController { - public static function RegisterHandler() { +class RegisterController +{ + public static function RegisterHandler() + { + if (isset($_POST['username'])) { + $hashedPassword = md5($_POST['password']); - $hashedPassword = md5($_POST['password']); + $newUser = array( + "name" => $_POST['name'], + "username" => $_POST['username'], + "email" => $_POST['email'], + "password" => $hashedPassword, + "phone" => $_POST['phone'], + "photo" => "http://www.simian-risk.com/wp-content/themes/custom/images/empty-profile.png", + "is_driver" => 0 + ); - $newUser = array( - "id" => 0, - "name" => $_POST['name'], - "username" => $_POST['username'], - "email" => $_POST['email'], - "password" => $hashedPassword, - "phone" => $_POST['phone'], - "photo" => "http://www.simian-risk.com/wp-content/themes/custom/images/empty-profile.png", - "is_driver" => 0 - ); + if (isset($_POST['is_driver'])) { + $newUser['is_driver'] = 1; + } - if (isset($_POST['is_driver'])) { - $newUser['is_driver'] = 1; + $pdo = DB::getInstance(); + User::InsertUser($newUser, $pdo); + //header untuk redirect + echo "<script> alert('Registrasi berhasil.');</script>"; } + require __DIR__."/../view/register.php"; + } + + public static function UsernameValidationHandler() + { + $usernameInput = $_REQUEST['q']; + $pdo = DB::getInstance(); - User::InsertUser($newUser, $pdo); - //header untuk redirect - echo "<script> alert('Registrasi berhasil.');</script>"; + if ($usernameInput !== "") { + if (User::GetUserBy("username", $usernameInput, $pdo)) { + echo "unavailable"; + } else { + echo "available"; + } + } + } + + public static function EmailValidationHandler() + { + $emailInput = $_REQUEST['q']; + + $pdo = DB::getInstance(); + if ($emailInput !== "") { + if (filter_var($emailInput, FILTER_VALIDATE_EMAIL)) { + if (User::GetUserBy("email", $emailInput, $pdo)) { + echo "unavailable"; + } else { + echo "available"; + } + } else { + echo "unavailable"; + } + } } -} +} \ No newline at end of file diff --git a/src/controller/UsernameValidationController.php b/src/controller/UsernameValidationController.php deleted file mode 100644 index 0a561a7a05c75d3e6c436b71a27407fd2c333f78..0000000000000000000000000000000000000000 --- a/src/controller/UsernameValidationController.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: iqbal - * Date: 05/10/17 - * Time: 23:12 - */ - -include_once __DIR__."/../model/User.php"; - -class UsernameValidationController { - public static function UsernameValidatiionHandler() { - - $usernameInput = $_REQUEST['q']; - - $pdo = DB::getInstance(); - if ($usernameInput !== "") { - if (User::GetUserBy("username", $usernameInput, $pdo)) { - echo "unavailable"; - } else { - echo "available"; - } - } - } -} \ No newline at end of file diff --git a/src/model/Driver.php b/src/model/Driver.php index 19b9c3c5372bbadc4697e407aafb980b5e13787e..dcbcce62e9ad71262b4b30c73839eb032b4d380b 100644 --- a/src/model/Driver.php +++ b/src/model/Driver.php @@ -23,4 +23,9 @@ class Driver extends User { } } + public static function InsertNewDriver(PDO $dbconn) { + $lastUser = $dbconn->query("SELECT * FROM user ORDER BY id DESC LIMIT 1")->fetch(PDO::FETCH_ASSOC); + $newId = $lastUser['id']; + $dbconn->prepare("INSERT INTO driver VALUES ($newId, 0, 0)")->execute(); + } } \ No newline at end of file diff --git a/src/model/User.php b/src/model/User.php index a62ca85ca40a653a3621e429f91ae6f3e39aab93..f81ba6510da4df253b671b59c363309892bad3c1 100644 --- a/src/model/User.php +++ b/src/model/User.php @@ -1,5 +1,8 @@ <?php +require_once __DIR__.'/../model/Driver.php'; + + class User { public $id; @@ -70,7 +73,7 @@ class User { $stmt = $conn->prepare("SELECT * FROM user WHERE $attribute='$value'"); $stmt->execute(); - $user = $stmt->fetchObject(); + $user = $stmt->fetchObject("User"); return $user; } catch (PDOException $e) { echo "Error: ".$e->getMessage(); @@ -97,8 +100,6 @@ class User { public static function InsertUser($user, PDO $conn) { try { - $lastUser = $conn->query("SELECT * FROM user ORDER BY id DESC LIMIT 1")->fetch(PDO::FETCH_ASSOC); - $newId = $lastUser['id'] + 1; $values = ""; $columns = ""; @@ -111,12 +112,11 @@ class User { $values .= $attr; } } - $columns = "id,".$columns; - $values = $newId.",".$values; $insertExpression = "INSERT INTO user ($columns) VALUES ($values)"; $conn->query($insertExpression); + Driver::InsertNewDriver($conn); } catch (PDOException $e) { echo "Error: ".$e->getMessage(); return false; diff --git a/src/route.php b/src/route.php index 05cc2b2bafccec2ab95a4780579b991b50c6a8b3..dd957e2d6f44a0a94552748eb82c763c1e96d2db 100644 --- a/src/route.php +++ b/src/route.php @@ -4,9 +4,14 @@ $AppInstance = Dagojek::Instance(); -$AppInstance->addRoute("/", 'MainController::DefaultHandler'); +$AppInstance->addRoute("/index.php/test", 'MainController::TestHandler'); + +$AppInstance->addRoute("/", 'MainController::LoginHandler'); $AppInstance->addRoute("/login", 'LoginController::LoginHandler'); -$AppInstance->addRoute("/register", 'MainController::DefaultHandler'); + +$AppInstance->addRoute("/register", 'RegisterController::RegisterHandler'); +$AppInstance->addRoute("/register/validate/username",'RegisterController::UsernameValidationHandler'); +$AppInstance->addRoute("/register/validate/email",'RegisterController::EmailValidationHandler'); $AppInstance->addRoute("/main/profil", 'ProfilController::ProfilHandler'); $AppInstance->addRoute("/main/profil/edit", 'ProfilController::EditHandler'); @@ -22,5 +27,7 @@ $AppInstance->addRoute("/main/order/new", 'OrderController::MakeOrderHa $AppInstance->addRoute("/main/order/finish", 'OrderController::FinishOrderHandler'); $AppInstance->addRoute("/main/history", 'MainController::DefaultHandler'); +$AppInstance->addRoute("/main/order/", 'MainController::DefaultHandler'); $AppInstance->addRoute("/main/order/select", 'MainController::DefaultHandler'); +$AppInstance->addRoute("/main/order/finish", 'MainController::DefaultHandler'); diff --git a/src/view/login.html b/src/view/login.html deleted file mode 100644 index 4d891b012b1de337732d8e75b14f58ee9257fd4f..0000000000000000000000000000000000000000 --- a/src/view/login.html +++ /dev/null @@ -1,43 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Login Page | Dagojek</title> - <link rel="stylesheet" type="text/css" href="style.css"> -</head> - -<body id="login-body"> - -<div class="container"> - - <header id="login-header"> - <h1>Dagojek Login</h1> - </header> - - <section id="login-main"> - <div id="login-panel"> - <form name="loginForm" method="post" action="/login"> - <fieldset> - <legend>Login:</legend> - Username: <br> - <input type="text" placeholder="Username" name="username"> - <br> - Password: <br> - <input type="password" placeholder="Password" name="password"> - <br> - <input type="submit" value="Login"> - <a id="register-link" href="register.html">Don't have an account?</a> - <br> - </fieldset> - </form> - </div> - </section> - - <footer> - - </footer> - -</div> - -</body> -</html> \ No newline at end of file diff --git a/src/view/login.php b/src/view/login.php new file mode 100644 index 0000000000000000000000000000000000000000..ac51ce26555ab0cb859ca1d0a5f6752284d712e1 --- /dev/null +++ b/src/view/login.php @@ -0,0 +1,41 @@ +<html> +<head> + <title>DAGO-JEK | Profil</title> + <link rel="stylesheet" type="text/css" href="/style.css"> +</head> +<body> +<div class="container"> + <div class="row"> + <div class="col-6 text-center"> + <h1>DAGOJEK<br> + <small>Welcome to go-jek rip-off!</small></h1> + </div> + </div> + + <div class="row"> + <div class="col-2"> + + </div> + <div class="col-2"> + <form method="post" action="/"> + <fieldset> + <legend>Login:</legend> + Username: <br> + <input class="login-input" type="text" placeholder="Username" name="username"> + <br> + Password: <br> + <input class="login-input" type="password" placeholder="Password" name="password"> + <br> + <input class="btn login-input" type="submit" value="Login"> + <a class="login-link" href="/index.php/register">Don't have an account?</a> + <br> + </fieldset> + </form> + </div> + <div class="col-2"> + + </div> + </div> +</div> +</body> +</html> \ No newline at end of file diff --git a/src/view/order.php b/src/view/order.php index 2a0760e021a5a3077c7f5185664fc092319b8b86..62c1c0cd4c39cb3129952e32ed59023f10d119ad 100644 --- a/src/view/order.php +++ b/src/view/order.php @@ -15,9 +15,9 @@ </div> </div> <div class="row"> - <a class="col-2 tab text-center active" href="/main/order?u=<?=$id?>">ORDER</a> - <a class="col-2 tab text-center" href="/main/hostory?u=<?=$id?>">HISTORY</a> - <a class="col-2 tab text-center" href="/main/profil?u=<?=$id?>">MY PROFILE</a> + <a class="col-2 tab text-center active" href="/index.php/main/order?u=<?=$id?>">ORDER</a> + <a class="col-2 tab text-center" href="/index.php/main/history?u=<?=$id?>">HISTORY</a> + <a class="col-2 tab text-center" href="/index.php/main/profil?u=<?=$id?>">MY PROFILE</a> </div> <div class="row"> <div class="col-6"><h1>MAKE AN ORDER</h1></div> diff --git a/src/view/profil.php b/src/view/profil.php index 7e1204240af893ebedb2165ddec6538f0d171604..a060cf229f765ee89acce0c7073aa6a628c85e60 100644 --- a/src/view/profil.php +++ b/src/view/profil.php @@ -15,13 +15,13 @@ </div> </div> <div class="row"> - <a class="col-2 tab text-center" href="/main/order?u=<?=$id?>">ORDER</a> - <a class="col-2 tab text-center" href="/main/hostory?u=<?=$id?>">HISTORY</a> - <a class="col-2 tab text-center active" href="/main/profil?u=<?=$id?>">MY PROFILE</a> + <a class="col-2 tab text-center" href="/index.php/main/order?u=<?=$id?>">ORDER</a> + <a class="col-2 tab text-center" href="/index.php/main/hostory?u=<?=$id?>">HISTORY</a> + <a class="col-2 tab text-center active" href="/index.php/main/profil?u=<?=$id?>">MY PROFILE</a> </div> <div class="row"> <div class="col-5"><h1>MY PROFILE</h1></div> - <div class="col-1 text-right"><a class="edit" href="/main/profil/edit?u=<?=$id?>"></a></div> + <div class="col-1 text-right"><a class="edit" href="/index.php/main/profil/edit?u=<?=$id?>"></a></div> </div> <div class="text-center profil"> <img class="img-circle" src="<?=$user->photo?>"/><br> @@ -38,7 +38,7 @@ <?php if ($user->isDriver) : ?> <div class="row"> <div class="col-5"><h2>PREFERED LOCATIONS</h2></div> - <div class="col-1 text-right"><a class="edit" href="/main/profil/location/edit?u=<?=$id?>"></a></div> + <div class="col-1 text-right"><a class="edit" href="/index.php/main/profil/location/edit?u=<?=$id?>"></a></div> </div> <div class="row"> <?php if ($location_count == 0): ?> diff --git a/src/view/profil_edit.php b/src/view/profil_edit.php index 12da5e7900f74b4121f40adf01aab02b5a63d803..a8e48a2c1b7c45ef86b95659f70b56ae5c2ef3ed 100644 --- a/src/view/profil_edit.php +++ b/src/view/profil_edit.php @@ -15,7 +15,7 @@ </div> </div> <div class="row"> - <form action="/main/profil/edit/save?u=<?=$id?>" method="post" enctype="multipart/form-data" onsubmit="return validateProfileEdit()"> + <form action="/index.php/main/profil/edit/save?u=<?=$id?>" method="post" enctype="multipart/form-data" onsubmit="return validateProfileEdit()"> <div class="container" style="width: 65%"> <div class="row"> <div class="col-6 text-left"> @@ -73,7 +73,7 @@ <br> <div class="row"> <div class="col-3 text-left"> - <a class="btn red" href="/main/profil?u=<?=$id?>">BACK</a> + <a class="btn red" href="/index.php/main/profil?u=<?=$id?>">BACK</a> </div> <div class="col-3 text-right"> <input class="btn green" type="submit" value="SAVE"> diff --git a/src/view/profil_edit_location.php b/src/view/profil_edit_location.php index 9a21605a4e0e7ecf95faaa23d93194d7a14701e9..4a1710d7346a29a2f81f2fb400b2ef480a5a67d3 100644 --- a/src/view/profil_edit_location.php +++ b/src/view/profil_edit_location.php @@ -42,7 +42,7 @@ <input id="input-location-<?=$no-1?>" class="input-location" type="text" style="width: 100%; line-height: 24px; padding-left:3px; font-size: medium; display: none;"></td> <td style="text-align: center"> <a id="action-edit-<?=$no-1?>" class="action-edit" onclick="editLocation(<?=$no-1?>)" data="<?=$no-1?>"></a> - <a class="action-delete" href="/main/profil/location/delete?u=<?=$id?>&name=<?=$data['location']?>" onclick="return confirm('Are you sure want to delete?')"></a> + <a class="action-delete" href="/index.php/main/profil/location/delete?u=<?=$id?>&name=<?=$data['location']?>" onclick="return confirm('Are you sure want to delete?')"></a> </td> </tr> <?php endforeach;?> @@ -61,7 +61,7 @@ <div class="row"> <div class="col-1"></div> <div class="col-4"> - <form action="/main/profil/location/add?u=<?=$id?>" method="post" onsubmit="return validateLocationEdit()"> + <form action="/index.php/main/profil/location/add?u=<?=$id?>" method="post" onsubmit="return validateLocationEdit()"> <input id="locationInput" type="text" name="location" style="width:76%;height: 30px; font-size: medium"> <input class="btn green" type="submit" value="ADD" style="width:20%;margin-left: 10px"> </form> @@ -72,13 +72,13 @@ <div class="row"> <div class="col-1"></div> <div class="col-4"> - <a class="btn red" href="/main/profil?u=<?=$id?>">BACK</a> + <a class="btn red" href="/index.php/main/profil?u=<?=$id?>">BACK</a> </div> <div class="col-1"></div> </div> </div> </div> </div> -<script type="text/javascript" src="/profil_edit.js"></script> +<script type="text/javascript" src="/index.php/profil_edit.js"></script> </body> </html> \ No newline at end of file diff --git a/src/view/register.html b/src/view/register.php similarity index 70% rename from src/view/register.html rename to src/view/register.php index 8438a3df9bfa4d20d1278c71ddce6a2a660e59a9..e2205db1d5cd5ea11b36ff3cd7b2efb6ec4d29b8 100644 --- a/src/view/register.html +++ b/src/view/register.php @@ -1,28 +1,26 @@ -<!DOCTYPE html> -<html lang="en"> +<html> <head> - <meta charset="UTF-8"> - <title>Register Page | Dagojek</title> - <link rel="stylesheet" type="text/css" href="style.css"> + <title>DAGO-JEK | Profil</title> + <link rel="stylesheet" type="text/css" href="/style.css"> </head> - -<body id="register-body"> - +<body> <div class="container"> + <div class="row"> + <div class="col-6 text-center"> + <h1>DAGOJEK<br> + <small>Create new account!</small></h1> + </div> + </div> - <header id="register-header"> - <h1> - Dagojek Register<br> - <small>Create New Account</small> - </h1> - </header> + <div class="row"> + <div class="col-2"> - <section id="register-main"> - <div id="register-panel"> - <form id="register-form" name="registerForm" method="post" action="../controller/RegisterController.php"> + </div> + <div class="col-2"> + <form id="register-form" method="post" action="/index.php/register"> <fieldset> <legend>Sign Up</legend> - <table> + <table id="register-table"> <tr> <td> Name: @@ -72,22 +70,19 @@ </td> </tr> </table> - <input type="checkbox" value="is-driver" name="is_driver"> I want to be a driver as well! + <input class="checkbox" id="driver-ckbox" type="checkbox" value="is-driver" name="is_driver"> I want to be a driver as well! <br> - <input id="sign-up-btn" type="submit" value="Sign up" disabled> + <a class="register-link" href="/index.php/login">Already have an account?</a> + <input class="btn" id="sign-up-btn" type="submit" value="Sign up" disabled> <br> </fieldset> </form> </div> - </section> - - <footer> - - </footer> + <div class="col-2"> + </div> + </div> </div> - -<!-- Script --> -<script type="application/javascript" src="script.js"></script> +<script type="application/javascript" src="/scripts.js"></script> </body> </html> \ No newline at end of file diff --git a/src/view/script.js b/src/view/script.js deleted file mode 100644 index ef52f8ebb5b84221116d7cf84bae413c5a59b5f1..0000000000000000000000000000000000000000 --- a/src/view/script.js +++ /dev/null @@ -1,103 +0,0 @@ -function checkAvailability(string, elmtID, dataCollection) { - var field = document.getElementById(elmtID); - - if (string.length === 0) { - field.classList.remove("available"); - field.classList.remove("unavailable"); - return; - } else { - var xmlhttp = new XMLHttpRequest(); - xmlhttp.onreadystatechange = function () { - if (this.readyState === 4 && this.status === 200) { - if (this.responseText === "available") { - field.classList.remove("unavailable"); - field.classList.add("available"); - } else { - field.classList.remove("available"); - field.classList.add("unavailable"); - } - } - }; - xmlhttp.open("GET", dataCollection + "?q=" + string, true); - xmlhttp.send(); - } -} - -function checkRequiredField(elmtID) { - var field = document.getElementById(elmtID); - - if (field.value === "") { - field.classList.add("empty-required"); - return false; - } else { - field.classList.remove("empty-required"); - return true; - } -} - -var isNameFilled = false; -var isUsernameFilled = false; -var isPasswordFilled = false; -var isEmailFilled = false; -var isPhoneFilled = false; -var isPasswordMatch = false; -var isUsernameAvailable = false; -var isEmailAvailable = false; - - -document.getElementById("confirm-password").onkeyup = function () { - var confirmField = document.getElementById("confirm-password"); - var passwordField = document.getElementById("password"); - - if (confirmField.value !== passwordField.value) { - confirmField.classList.add("not-match"); - passwordField.classList.add("not-match"); - isPasswordMatch = false; - } else { - confirmField.classList.remove("not-match"); - passwordField.classList.remove("not-match"); - isPasswordMatch = true; - } -}; - - -document.getElementById("name").onkeyup = function () { - isNameFilled = checkRequiredField("name"); -}; - -document.getElementById("username").onkeyup = function () { - isUsernameFilled = checkRequiredField("username"); - checkAvailability(this.value, "username", '../controller/UsernameValidationController.php'); - isUsernameAvailable = this.classList.contains("available"); -}; - -document.getElementById("password").onkeyup = function () { - isPasswordFilled = checkRequiredField("password"); -}; - -document.getElementById("email").onkeyup = function () { - isEmailFilled = checkRequiredField("email"); - checkAvailability(this.value, "email", '../controller/EmailValidationController.php'); - isEmailAvailable = this.classList.contains("available"); -}; - -document.getElementById("phone").onkeyup = function () { - isPhoneFilled = checkRequiredField("phone"); -}; - -document.getElementById("register-form").onkeyup = function () { - var submitBtn = document.getElementById("sign-up-btn"); - - if (isNameFilled && - isUsernameFilled && - isPasswordFilled && - isEmailFilled && - isPhoneFilled && - isPasswordMatch && - isUsernameAvailable && - isEmailAvailable) { - submitBtn.removeAttribute("disabled"); - } else { - submitBtn.setAttribute("disabled", "true"); - } -}; \ No newline at end of file diff --git a/src/view/style.css b/src/view/style.css deleted file mode 100644 index 26a76968eaa8ba8b31f1bae61e4e04505ab45e62..0000000000000000000000000000000000000000 --- a/src/view/style.css +++ /dev/null @@ -1,40 +0,0 @@ -#login-body, #register-body { - background-color: #333333; - color: #ffffff; -} - -#login-header, #register-header { - text-align: center; - margin-top: 50px; -} - - -#login-main, #register-main { - horiz-align: center; - width: 25%; - height: 60%; - margin: 0 auto; -} - -#register-link { - float: right; - color: #f4df42; - margin-top: 0.3em; -} - -.available { - background-color: greenyellow; -} - -.unavailable, .empty-required, .not-match { - background-color: orangered; -} - -.not-match::-webkit-input-placeholder, .empty-required::-webkit-input-placeholder, .unavailable::-webkit-input-placeholder { - color: whitesmoke; -} - -input { - margin-top: 5px; - margin-bottom: 5px; -} \ No newline at end of file