public function loginUser() { // Affecter une variable à chaque valeur clé de $_POST $email = trim(htmlentities($_POST['email'])); $password = trim(htmlentities($_POST['password'])); // Initialisation d'un tableau d'erreurs (associatif) $errors = []; // Instanciation d'un object de type UserManager $userManager = new UserManager(); $userManager->setTable('users'); // Bug du framework le nom de la table est mal défini $resultUser = $userManager->getUserByUsernameOrEmail($email); if ($resultUser) { // Instanciation d'un object de type AuthentificationManager $authentificationManager = new AuthentificationManager(); // Cette méthode teste si le mot de passe est valide, $password ici est en clair if ($authentificationManager->isValidLoginInfo($email, $password)) { $authentificationManager->logUserIn($resultUser); // Redirection $this->redirectToRoute('seekrun'); } else { $errors['login'] = "******"; } } else { $errors['login'] = "******"; } $this->show('run/seekrun', ['errors' => $errors]); }
public function login() { // connexion au site if (isset($_SESSION['user'])) { $this->redirectToRoute('accueil'); // si ok envoie page 2 } if (isset($_POST['connexion'])) { $auth = new AuthentificationManager(); $userManager = new UserManager(); $UserManagerSuite = new GeneralManager(); //debug($userManager); die; // vérification if ($auth->isValidLoginInfo($_POST['wuser']['mail'], $_POST['wuser']['mot_de_passe'])) { //selection table user $user_part1 = $userManager->getUserByUsernameOrEmail($_POST['wuser']['mail']); //recuperation de l'id de l'utilisateur connecté et jointure avec les autres tables. $id_user = $user_part1['id']; if ($user_part1['validation_inscription'] === 'true') { $user_part2 = $UserManagerSuite->findAllLogUser($id_user); $user = array_merge($user_part1, $user_part2); // ajout de $user2 dans $user $auth->logUserIn($user); //debug($_SESSION['user']);die(); // vérification $this->redirectToRoute('accueil'); } else { $this->show('home/home'); } } } $this->show('home/home'); }
public function login() { if (isset($_POST['create'])) { $auth = new AuthentificationManager(); $userManager = new UserManager(); if ($auth->isValidLoginInfo($_POST['myform']['username'], $_POST['myform']['password'])) { $user = $userManager->getUserByUsernameOrEmail($_POST['myform']['username']); $auth->logUserIn($user); $this->redirectToRoute('home'); } } $this->show('default/login'); }
/** * Vérifie qu'une combinaison d'email/username et mot de passe (en clair) sont présents en bdd et valides * @param string $usernameOrEmail Le pseudo ou l'email à test * @param string $plainPassword Le mot de passe en clair à tester * @return int 0 si invalide, l'identifiant de l'utilisateur si valide */ public function isValidLoginInfo($usernameOrEmail, $plainPassword) { $app = getApp(); $userManager = new UserManager(); $usernameOrEmail = strip_tags(trim($usernameOrEmail)); $foundUser = $userManager->getUserByUsernameOrEmail($usernameOrEmail); if (!$foundUser) { return 0; } if (password_verify($plainPassword, $foundUser[$app->getConfig('security_password_property')])) { return (int) $foundUser['id']; } return 0; }
public function profilModif() { $manager = new ProfilManager(); $manager2 = new WuserManager(); $manager3 = new UserManager(); if (isset($_POST)) { $id = $_POST['id']; $mail = $_POST['mail']; $telephone = $_POST['telephone']; $facebook = $_POST['facebook']; $twitter = $_POST['twitter']; $googleplus = $_POST['googleplus']; $linkedin = $_POST['linkedin']; $github = $_POST['github']; $profil = $manager->getUserProfil($id); if (empty($mail) || $manager3->getUserByUsernameOrEmail($mail) || !preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4}\$#", $mail)) { $mail = $profil['mail']; } if (empty($telephone)) { $telephone = $profil['telephone']; } if (empty($facebook)) { $facebook = $profil['facebook']; } if (empty($twitter)) { $twitter = $profil['twitter']; } if (empty($googleplus)) { $googleplus = $profil['googleplus']; } if (empty($linkedin)) { $linkedin = $profil['linkedin']; } if (empty($github)) { $github = $profil['github']; } $manager->setProfilModif($id, $telephone, $facebook, $twitter, $googleplus, $linkedin, $github); $manager2->setWuserModif($id, $mail); $this->redirectToRoute('profil', ['id' => $id]); } }
/** * Authentification */ public function auth() { // récupération d'un objet sécurité $auth = new AuthentificationManager(); // vérification login/password if ($auth->isValidLoginInfo(htmlentities($_POST['email']), htmlentities($_POST['password']) ) ) { // récupération d'un objet utilisateur $user = new UserManager; // récupération des infos de l'utilisateur en cours $util = $user->getUserByUsernameOrEmail(htmlentities($_POST['email'])); // connexion de l'utilisateur $auth->logUserIn($util); // SESSION // appel du modèle ClientManager $client = new \Manager\ClientManager(); $allClient = $client->utilisateurClient(); $_SESSION['user']['idClient'] = $allClient['id']; $_SESSION['user']['nom'] = $allClient['nomClient']; $_SESSION['user']['prenom'] = $allClient['prenomClient']; $_SESSION['user']['adresse'] = $allClient['adresseClient']; $_SESSION['user']['cp'] = $allClient['cpClient']; $_SESSION['user']['ville'] = $allClient['villeClient']; $_SESSION['user']['tel'] = $allClient['telClient']; //redirection vers une page privée $this->redirectToRoute('prive'); } else { // si non valide retour au formulaire $this->redirectToRoute('home'); } }
/** * Authentification */ public function checkLogin() { // récupération d'un objet sécurité $auth = new AuthentificationManager(); // récupération d'un objet utilisateur $user = new UserManager(); // récupération des infos de l'utilisateur en cours $util = $user->getUserByUsernameOrEmail(htmlentities($_POST['username'])); // vérification login/password if ($auth->isValidLoginInfo(htmlentities($_POST['username']), htmlentities($_POST["password"]))) { // connexion de l'utilisateur $auth->logUserIn($util); //redirection vers une page privée (ou admin, en fonction des privilèges) if ($_SESSION["user"]["role"] == "Administrateur") { $this->redirectToRoute('admin'); } else { $this->close(); $this->redirectToRoute('home'); } } else { $this->redirectToRoute('home'); } }
public function loginUser() { $email = trim(htmlentities($_POST['email'])); $password = trim(htmlentities($_POST['password'])); $errors = []; $userManager = new UserManager(); $userManager->setTable('users'); $resultUser = $userManager->getUserByUsernameOrEmail($email); // debug($resultUser); // die(); if ($resultUser) { $authentificationManager = new AuthentificationManager(); if ($authentificationManager->isValidLoginInfo($email, $password)) { $authentificationManager->logUserIn($resultUser); $this->redirectToRoute('home'); } else { $errors['login'] = "******"; } } else { $errors['login'] = "******"; } $this->show('login/index', ['errors' => $errors]); }
public function login() { $flagl = 0; $manager2 = new ProfilManager(); if (isset($_POST['loginform'])) { $auth = new AuthentificationManager(); $userManager = new UserManager(); if ($auth->isValidLoginInfo($_POST['myform']['mail'], $_POST['myform']['mdp'])) { $user = $userManager->getUserByUsernameOrEmail($_POST['myform']['mail']); $result = $auth->logUserIn($user); $flagl = 1; $manager2->userIsOnline($user['id']); $this->redirectToRoute('home', ['flagl' => $flagl]); } else { $error = 'Connexion impossible.'; $this->show('default/home', ['error' => $error]); } } $this->show('default/home', ['flag' => $flag]); }
/** * Réinitialisation du mot de passe */ public function envoimdp() { //récupération d'un objet utilisateur $utilisateur = new \Manager\UtilisateurManager(); //création d'un objet user $user = new UserManager; //netoyage de l'email saisie $userMail = htmlentities($_POST['mailOublie']); // recup des infos de l'utilisateur grace à l'email $userInfo = $user->getUserByUsernameOrEmail($userMail); // recup de l'id utilisateur $idUser = $userInfo['id']; // generation aléatoire d'un nouveau mot de passe $newMdp = \W\Security\StringUtils::randomString(32); // création d'un tableau contenant le nouveau mot de passe // crypter avec password_hash $tUtilisateur = ['password' => password_hash($newMdp, PASSWORD_DEFAULT)]; // update dans la base $utilisateur->update($tUtilisateur, $idUser, $stripTags = true); // afficher le formulaire $this->show('utilisateur/oubliemdp', array('userMail'=>$userMail, 'mdp'=>$newMdp)); }