public function indexAction() { header('content-type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST'); $valid = true; $errors = []; $username = trim(ucwords(strtolower(htmlentities($_POST['username'])))); $password = hash('sha256', strrev(ProfileModel::getTimestamp($this->pdo, $username)) . htmlentities($_POST['password']) . '\\Rand0msalT/'); if (!isset($username) || empty($username)) { $errors['username'] = '******'; $valid = false; } elseif (SigninModel::checkUsername($this->pdo, $username) !== $username) { $errors['username'] = '******'existe pas</span>'; $valid = false; } elseif (!isset($password) || empty($password)) { $errors['password'] = '******'; $valid = false; } elseif (SigninModel::getPassword($this->pdo, $username) !== $password) { $errors['password'] = '******'; $valid = false; } $errors['valid'] = $valid; if ($valid) { if (isset($_POST['remember'])) { CookieController::create($this->pdo, $username, $password); } AuthModel::authUser($this->pdo, $username, $password); } echo json_encode($errors); }
public static function run() { if (!($user = CookieController::readSessionCookie())) { header("Location: home"); } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { if (UserDatabase::updateUser($user, $_POST)) { # First Name if (isset($_POST["firstName"])) { $firstName = $_POST["firstName"]; if (strcmp($firstName, $user->getFirstName()) !== 0) { $user->setFirstName($firstName); } } # Last Name if (isset($_POST["lastName"])) { $lastName = $_POST["lastName"]; if (strcmp($lastName, $user->getLastName()) !== 0) { $user->setLastName($lastName); } } # Email if (isset($_POST["email"])) { $email = $_POST["email"]; if (strcmp($email, $user->getEmail()) !== 0) { $user->setEmail($email); } } # Handle if (isset($_POST["handle"])) { $handle = $_POST["handle"]; if (strcmp($handle, $user->getHandle()) !== 0) { $user->setHandle($handle); } } # About if (isset($_POST["about"])) { $about = $_POST["about"]; if (strcmp($about, $user->getAbout()) !== 0) { $user->setAbout($about); } } # Password if (isset($_POST["cur-password"]) && isset($_POST["new-password"]) && isset($_POST["confirm-password"])) { $curPassword = $POST["cur-password"]; echo $curPassword; $newPassword = $POST["new-password"]; $confirmPassword = $POST["confirm-password"]; if (strcmp($curPassword, $newPassword) !== 0) { $user->setPassword($curPassword, $newPassword, $confirmPassword); } } CookieController::setSessionCookie($user); header("Location: view-profile"); } else { EditProfileView::show($user); } } else { EditProfileView::show($user); } }
public static function refreshSessionCookie() { if (CookieController::cookieExists("session")) { $user = CookieController::readSessionCookie(); CookieController::setSessionCookie($user); return $user; } return false; }
public static function run() { if (CookieController::cookieExists("session")) { if (($user = CookieController::refreshSessionCookie()) === false) { header("Location: home"); } else { ProfileView::show($user); } } else { header("Location: home"); } }
public static function run() { if (CookieController::cookieExists("session")) { if (($user = CookieController::refreshSessionCookie()) === false) { echo "<h1>No User Found</h1><hr/>"; LogInController::run(null); } else { DashboardView::show($user); } } else { LandingView::show(null); } }
public static function run() { if (CookieController::cookieExists("session")) { if (($user = CookieController::readSessionCookie()) === false) { header("Location: home"); } else { $maps = MapDatabase::getAllUserMaps($user->getID()); MyTripsView::show($maps); } } else { header("Location: home"); } }
public static function authCookie($pdo, $username, $password) { $q = $pdo->prepare(' SELECT * FROM users WHERE username = :username '); $q->bindParam(':username', $username); $q->execute(); $result = $q->fetch(); if (hash('sha256', $result['password']) === $password) { $_SESSION['auth'] = $result; } else { CookieController::destroy(); } }
public static function run() { if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST["handle"]) && isset($_POST["password"])) { $handle = $_POST["handle"]; $password = $_POST["password"]; if (UserDatabase::validatePassword($handle, $password)) { $user = UserDatabase::getUserByHandle($handle); if (CookieController::setSessionCookie($user)) { header("Location: dashboard"); } else { $user->setError("login", "LOG_IN_FAILED"); LogInController::show($user); } } else { LogInView::show(null); } } } else { LogInView::show(null); } }
public static function run($map) { if (CookieController::cookieExists("session")) { if (($user = CookieController::readSessionCookie()) !== false) { $map; if ($_SERVER["REQUEST_METHOD"] == "POST") { $mapID = ""; $mapName = ""; $latLng = ""; if (isset($_POST["map-id"])) { $mapID = $_POST["map-id"]; } if (isset($_POST["map-name"])) { $mapName = $_POST["map-name"]; } if (isset($_POST["lat-lng"])) { $latLng = $_POST["lat-lng"]; } $map = new Map($mapID, $mapName, $latLng); if (empty($mapID)) { MapDatabase::addMap($map, $user->getID()); } else { MapDatabase::updateMap($map); } MapView::show($map); } else { if (isset($_GET["selection"])) { $mapID = $_GET["selection"]; $map = MapDatabase::getMap($mapID); } MapView::show($map); } } else { header("Location: home"); } } else { header("Location: home"); } }
public static function run() { CookieController::removeCookie("session"); header("Location: home"); }
include "../includer.php"; $params = array("firstName" => "John", "lastName" => "Cena", "email" => "*****@*****.**", "handle" => "johnCena", "about" => "Wrestling Champion"); $user = new User($params); $user->resetErrors(); echo "<h1>setSessionCookie():<hr/>"; if (!CookieController::setSessionCookie($user)) { echo "<h3>Failure: returned false</h3>"; } elseif (is_null($_COOKIE) || !isset($_COOKIE["session"])) { echo "<h3>Failure: \$_COOKIE is null or session is not set</h3>"; } else { echo "<h3>Success</h3>"; } echo "<h1>readSessionCookie():<hr/>"; if (!($user = CookieController::readSessionCookie($user))) { echo "<h3>Failure</h3>"; } elseif (empty($user->getFirstName())) { echo "<h3>Failure</h3>"; } else { echo "<h3>Success</h3>"; } echo "<h1>refreshSessionCookie():<hr/>"; if (!($user = CookieController::refreshSessionCookie($user))) { echo "<h3>Failure</h3>"; } elseif (empty($user->getFirstName())) { echo "<h3>Failure</h3>"; } else { echo "<h3>Success</h3>"; } ?> </body> </html>