<?php if (isset($_POST['action'])) { if ($_POST['action'] == "register") { if (isset($_POST['f-name'], $_POST['l-name'], $_POST['email'], $_POST['emailRepeat'], $_POST['password'], $_POST['passwordRepeat'])) { $lastname = $_POST['l-name']; $firstname = $_POST['f-name']; $email = $_POST['email']; $emailRepeat = $_POST['emailRepeat']; $userManager = new UserManager($database); try { $data = $userManager->create($_POST['l-name'], $_POST['f-name'], $_POST['password'], $_POST['passwordRepeat'], $_POST['email'], $_POST['emailRepeat']); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $_SESSION['success'] = "Votre inscription est réussite!"; $_SESSION['id'] = $data->getId(); header("Location: index.php"); exit; } else { return $errors; } } } else { if ($_POST['action'] == "connect") { if (isset($_POST['email'], $_POST['password'])) { $email = $_POST['email']; $userManager = new UserManager($database); try { $user = $userManager->findByEmail($_POST['email']);
} else { $user = $retour; if ($user->verifPassword($_POST['password'])) { $_SESSION['id'] = $user->getId(); header('Location: index.php'); exit; } else { $errors[] = 'Incorrect Password'; } } } } else { if ($action == 'register') { if (isset($_POST['login'], $_POST['password1'], $_POST['password2'], $_POST['email'], $_POST['avatar'])) { $manager = new UserManager($db); $retour = $manager->create($_POST['login'], $_POST['password1'], $_POST['password2'], $_POST['email'], $_POST['avatar']); if (is_array($retour)) { $errors = array_merge($errors, $retour); } else { header('Location: index.php?page=login'); exit; } } } else { if ($action == 'logout') { session_destroy(); $_SESSION = array(); header('Location: index.php'); exit; } else { if ($action == 'edit_profil') {
} else { $user = $retour; if ($user->verifPassword($_POST['password'])) { $_SESSION['id'] = $user->getId(); header('Location: index.php'); exit; } else { $errors[] = 'Incorrect Password'; } } } } else { if ($action == 'register') { if (isset($_POST['login'], $_POST['password1'], $_POST['password2'], $_POST['email'], $_POST['name'], $_POST['surname'], $_POST['date_birth'])) { $manager = new UserManager($db); $retour = $manager->create($_POST['login'], $_POST['password1'], $_POST['password2'], $_POST['email'], $_POST['name'], $_POST['surname'], $_POST['date_birth']); if (is_array($retour)) { $errors = array_merge($errors, $retour); } else { if (is_string($retour)) { $errors[] = $retour; } else { header('Location: index.php?page=login'); exit; } } } } else { if ($action == 'logout') { session_destroy(); $_SESSION = array();
<?php if (isset($_GET['page'])) { // Register function if ($_GET['page'] == 'register') { if (isset($_POST['register_email'], $_POST['register_name'], $_POST['register_surname'], $_POST['register_password'], $_POST['register_password2'])) { $manager = new UserManager($db); try { $res = $manager->create($_POST['register_email'], $_POST['register_name'], $_POST['register_surname'], $_POST['register_password'], $_POST['register_password2']); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $_SESSION['success'] = "Registration successful"; header('Location: ?page=login'); exit; } } } // Login function if ($_GET['page'] == 'login') { if (isset($_POST['login_email'], $_POST['login_password'])) { $userManager = new UserManager($db); try { $user = $userManager->readByEmail($_POST['login_email']); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { if ($user->checkPassword($_POST['login_password'])) { $_SESSION['id'] = $user->getId();
$login = $_POST['login']; $email = $_POST['email']; } elseif ($taille > $taille_maxi) { $error = 'Le fichier est trop gros.'; $login = $_POST['login']; $email = $_POST['email']; } elseif ($error == "") { //On formate le nom du fichier ici... $fichier = strtr($fichier, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy'); $fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier); if (move_uploaded_file($_FILES['image']['tmp_name'], $dossier . $fichier) == FALSE) { $error = 'Echec de l\'upload !'; $login = $_POST['login']; $email = $_POST['email']; } else { $user = $manager->create($_POST['login'], $_POST['email'], $_POST['password'], $dossier . $fichier); header('Location:' . str_replace('index.php', '', $_SERVER['SCRIPT_NAME']) . 'login'); exit; } } } else { $error = "Les deux mots de passe ne correspondent pas"; $login = $_POST['login']; $email = $_POST['email']; } } else { $error = "Le mot de passe doit contenir 6 caractères minimum"; $login = $_POST['login']; $email = $_POST['email']; } }