<?php require_once '../autoload.php'; require_once '../include/results.php'; if (isset($_POST['bouton-info'])) { $validator = new Validator($_POST); foreach ($_POST as $field => $post) { if (!empty($_POST[$field]) && $_POST[$field] != 'Enregistrer les modifications') { if ($_POST['username']) { $validator->isAlpha('username', "Votre username n'est pas valide"); $info_user->username = $_POST['username']; } if ($_POST['biography']) { $validator->isAlpha('biography', "Votre biography n'est pas valide"); $info_user->biography = $_POST['biography']; } if ($_POST['nickname']) { $validator->isAlpha('nickname', "Votre nickname n'est pas valide"); $info_user->nickname = $_POST['nickname']; } if ($_POST['location']) { $validator->isAlpha('location', "Votre location n'est pas valide"); $info_user->location = $_POST['location']; } if ($_POST['birthdate']) { $validator->isDate('birthdate', "Votre birthdate n'est pas valide"); $info_user->birthdate = $_POST['birthdate']; } if ($validator->isValid()) { $auth->update($db, $user_id, htmlspecialchars($post), htmlspecialchars($field)); } else {
<?php require_once 'inc/bootstrap.php'; if (!empty($_POST)) { $db = theApp::getDataBase(); $errors = array(); $validator = new Validator($_POST); $validator->isAlpha('username', 'Votre pseudo n\'est pas valide, il doit etre au format AlphaNumérique'); if ($validator->isValid()) { $validator->isUniq('username', $db, 'users', 'Ce pseudo est déjà utilisé'); } $validator->isEmail('email', 'Votre email n\'est pas valide'); if ($validator->isValid()) { $validator->isUniq('email', $db, 'users', 'Cet Email est deja utilisé pour un autre compte!'); } $validator->isConfirmPWD('password', 'Vos deux mots de passe ne sont pas les mêmes'); if ($validator->isValid()) { $auth = theApp::getAuth(); $auth->register($db, $_POST['username'], $_POST['password'], $_POST['email']); $session = Session::getInstance(); $session->setFlash('success', 'un email de confirmation vous a été envoyé!'); header('Location: login.php'); exit; } else { $errors = $validator->getErrors(); } } require 'inc/header.php'; ?> <h1>S'inscrire</h1>
$game = unserialize($_SESSION['game']); } // if 'Games' is clicked, show all games saved in db if (isset($_GET['games'])) { $games = $db->raw(' SELECT games.id, username, word, start_datetime, score FROM games INNER JOIN users ON user_id=users.id INNER JOIN words ON word_id=words.id; '); buildView('user/games', compact('games')); exit; } // if 'Guess' is clicked, guess letter if (isset($_POST['guess'])) { $letter = $_POST['letter']; if (Validator::notEmpty($letter) && Validator::isAlpha($letter) && Validator::maxLength($letter, 1)) { try { $game->guessLetter($letter); $_SESSION['game'] = serialize($game); //sync game obj with session } catch (Exception $e) { $message = $e->getMessage(); buildView('user/index', compact('game', 'message')); exit; } header('Location: .'); exit; } else { $message = 'Insert letter only!'; buildView('user/index', compact('game', 'message')); }
<?php require_once 'autoload.php'; $db = App::getDatabase(); $auth = App::getAuth(); if ($auth->user()) { App::redirect('controller/accueil.php'); } $errors = []; if (!empty($_POST['bouton-register'])) { $validator = new Validator($_POST); $validator->isAlpha('username', "Votre pseudo n'est pas valide"); $validator->isEmail('email', "Votre email n'est pas valide"); $validator->isUniq('username', $db, 'users', 'Ce pseudo est déjà pris'); $validator->isUniq('email', $db, 'users', 'Cet email est déjà utilisé pour un autre compte'); if ($validator->isValid()) { $avatar = '../view/img/avatar/owl.png'; App::getAuth()->register($db, htmlspecialchars($_POST['username']), htmlspecialchars($_POST['register-password']), htmlspecialchars($_POST['email'])); Session::getInstance()->setFlash('success', 'Un email de confirmation vous a été envoyé pour valider votre compte'); App::redirect('index.php'); } else { $errors = $validator->getErrors(); } } if (!empty($_POST['bouton-login'])) { $user = $auth->login($db, htmlspecialchars($_POST['username']), htmlspecialchars($_POST['password'])); $session = Session::getInstance(); if ($user) { $session->setFlash('success', 'Vous êtes maintenant connecté'); $user_id = $_SESSION['auth']->id_user; App::redirect("controller/accueil.php");
<?php require_once 'inc/bootstrap.php'; // Je veux récupérer le premier utilisateur if (!empty($_POST)) { $errors = array(); $db = App::getDatabase(); $validator = new Validator($_POST); $validator->isAlpha('username', "Votre pseudo n'est pas valide (alphanumérique)"); if ($validator->isValid()) { $validator->isUniq('username', $db, 'users', 'Ce pseudo est déjà pris'); } $validator->isEmail('email', "Votre email n'est pas valide"); if ($validator->isValid()) { $validator->isUniq('email', $db, 'users', 'Cet email est déjà utilisé pour un autre compte'); } $validator->isConfirmed('password', 'Vous devez rentrer un mot de passe valide'); if ($validator->isValid()) { App::getAuth()->register($db, $_POST['username'], $_POST['password'], $_POST['email']); Session::getInstance()->setFlash('success', 'Un email de confirmation vous a été envoyé pour valider votre compte'); App::redirect('index.php'); } else { $errors = $validator->getErrors(); } } ?> <?php require 'inc/header.php'; ?>
if ($user->isAdmin) { header('Location: /admin.php'); exit; } header('Location: /'); exit; } } } // if 'Register' is clicked if (isset($_POST['register'])) { $name = trim($_POST['name']); $username = trim($_POST['username']); $password = trim($_POST['password']); // validate input if (V::notEmpty($name) && V::isAlpha($name) && V::maxLength($name, 20) && V::notEmpty($username) && V::isUsername($username) && V::maxLength($username, 20) && V::notEmpty($password) && V::maxLength($password, 20)) { // if input ok register user and force login $user = new User($name, $username, $password); $auth = new Auth($db, $user); $password = $auth->register(); /*echo '<pre>'; var_dump($auth); echo '</pre>';exit;*/ $auth->forceLogin($password); header('Location: /'); exit; } else { $message = 'Correct your input and try again.'; buildView('auth/register', compact('message')); exit; }
exit; } // if 'Add' is clicked add new word if (isset($_POST['addWord'])) { $word = $_POST['word']; if (Validator::isAlpha($word) && Validator::maxLength($word, 20)) { $db->insert('words', ['word' => mb_strtoupper($word)]); header('Location: /admin.php?words'); exit; } else { $words = $db->selectAll('words'); $message = 'Only letters and length < 20 please.'; buildView('admin/words', compact('words', 'message')); exit; } } // if admin edits word, update it with AJAX if (isset($_POST['name'])) { $newValue = $_POST['value']; if (Validator::isAlpha($newValue) && Validator::maxLength($newValue, 20)) { $db->update('words', ['word' => mb_strtoupper($newValue)], $_POST['pk']); http_response_code(200); exit; } else { http_response_code(400); header('Content-type: application/json'); echo json_encode('Only letters and length < 20 please.'); exit; } } buildView('admin/index');