Skip to content
Snippets Groups Projects
Commit 3bc6d7be authored by Iqbal's avatar Iqbal
Browse files

Fixed login and register functionality.

parent a01ba074
Branches
2 merge requests!7Routing Configuration with index.php,!6Reconfigure Login and Register Page
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
......@@ -2,30 +2,42 @@
/**
* Created by PhpStorm.
* User: iqbal
* Date: 04/10/17
* Time: 16:29
* Date: 06/10/17
* Time: 13:22
*/
session_start();
require_once __DIR__.'/../model/User.php';
include_once "Controller.php";
include_once "../model/User.php";
class LoginController
{
public static function LoginHandler()
{
session_start();
$pdo = DB::getInstance();
$userData = User::GetAllUsernameAndPassword($pdo);
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'] = "";
header("Location: ../view/login.html");
exit;
}
if (isset($_GET['logout'])) {
$_SESSION['username'] = "";
header("Location: /");
exit;
}
if (isset($userData)) {
if ($userData->password === $password) {
$_SESSION['username'] = $username;
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>";
} else {
echo "<script type='application/javascript'> alert('Username atau password salah'); </script>";
echo "<script type='application/javascript'> alert('Login berhasil'); </script>";
} else {
echo "<script type='application/javascript'> alert('Username atau password salah'); </script>";
}
}
}
\ No newline at end of file
require __DIR__."/../view/login.php";
}
}
\ No newline at end of file
......@@ -3,8 +3,7 @@
class MainController {
public static function LoginHandler() {
header("Location: http://dagojek.com/src/view/login.html");
die();
LoginController::LoginHandler();
}
public static function DefaultHandler() {
......
......@@ -2,31 +2,72 @@
/**
* Created by PhpStorm.
* User: iqbal
* Date: 05/10/17
* Time: 16:43
* Date: 07/10/17
* Time: 0:40
*/
include_once "Controller.php";
include_once "../model/User.php";
require_once __DIR__.'/../model/User.php';
$hashedPassword = md5($_POST['password']);
class RegisterController
{
public static function RegisterHandler()
{
if (isset($_POST['username'])) {
$hashedPassword = md5($_POST['password']);
$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
);
$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";
}
$pdo = DB::getInstance();
User::InsertUser($newUser, $pdo);
//header untuk redirect
echo "<script> alert('Registrasi berhasil.');</script>";
\ No newline at end of file
public static function UsernameValidationHandler()
{
$usernameInput = $_REQUEST['q'];
$pdo = DB::getInstance();
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment