function login() { if (!empty($_POST["txtPassword"]) and !empty($_POST["txtUserName"]) or isset($_COOKIE["userToken"])) { // Appel à la base de données pour valider les données de connexion if (!isset($_COOKIE["userToken"])) { $userId = Users::getUserIdByName(strtolower($_POST["txtUserName"])); } else { $userId = Users::getUserIdByToken($_COOKIE["userToken"]); } if ($userId != -1) { // Le nom d'utilisateur existe $user = Users::getUser($userId); $tokenCode = ""; if (isset($_COOKIE["userToken"])) { $token = Users::getTokenByUserId($userId); if (Users::getTokenEndDate($token) > time()) { $tokenCode = $token; } else { Users::deleteCookieToken($userId); $tokenCode = "none"; } } if (!empty($_POST["txtPassword"]) and crypt($_POST["txtPassword"], $user["UserSalt"]) == $user["UserHash"] or isset($_COOKIE["userToken"]) and $_COOKIE["userToken"] == $tokenCode) { // Mot de passe correct if (isset($_SESSION["path"])) { $path = $_SESSION["path"]; $_SESSION["path"] = ""; header('Location:' . $path); } else { if (!Users::isUserAdmin($userId)) { if (Users::isUserActivated($userId)) { self::setSessionAndCookie($userId); if ($_SESSION["role"] == ROLE_FAMOWNER or $_SESSION["role"] == ROLE_MOD) { header(MOD_HEADER); } else { //usager normal header(OBJECTS_HEADER); } } else { $_SESSION = array(); $data = array("Inactivated" => true); $this->renderTemplate(file_get_contents(CONNECTION_PAGE), $data); } } else { // L'utilisateur est un administrateur système self::setSessionAndCookie($userId); header(SYSADMIN_HEADER); } } } else { // Mot de passe incorrect $data = array("Error" => true); $this->renderTemplate(file_get_contents(CONNECTION_PAGE), $data); } } else { // Mot de passe incorrect $data = array("Error" => true); $this->renderTemplate(file_get_contents(CONNECTION_PAGE), $data); } } else { // Mot de passe incorrect $data = array("Error" => true); $this->renderTemplate(file_get_contents(CONNECTION_PAGE), $data); } }