public static function addUser($db, $login, $password, $firstName, $familyName) { $instance = new self($db); $hash = $instance->generateRegisterHash($login); $password = password_hash($password, PASSWORD_DEFAULT); if ($instance->isLoginAvailable($login)) { $result = $instance->myDB->query($instance->SQL_CREATE_USER, array('login' => $login, 'password' => $password, 'familyName' => $familyName, 'firstName' => $firstName, 'hash' => $hash)); if ($result != 0) { $instance->userId = $instance->myDB->lastInsertId(); $instance->username = $login; require "../misc/registrationMail.php"; require "../misc/mailFunc.php"; sendRegistrationMail($login, $hash); return $instance; } } return null; }
$date = new DateTime(); $timestamp = $date->getTimestamp(); $logday = date('Y-m-d H:i:s', $timestamp); $key = hash('md5', $timestamp . $email); $req = $bdd->prepare(' INSERT INTO `wdidy-user`(IDuser,email,firstname,lastname,country,city,password,logday) VALUES(:IDuser,:email,:firstname,:lastname,:country,:city,:password,:logday) '); $req->execute(array('IDuser' => $key, 'email' => $email, 'firstname' => $name, 'lastname' => $lastname, 'country' => $country, 'city' => $city, 'password' => $password, 'logday' => $logday)); // Préparation du mail contenant le lien d'activation $destinataire = $email; $sujet = "Activate your account"; $entete = "From: basedonney@wdidy.com"; // Le lien d'activation est composé du login(adresse mail) et de la clé(key) $message = "<html><head></head><body><b>Welcome to WDIDY</b><br> <br>" . "To activate your account, click on the link below or copy/paste the url in your favorite browser<br> <br>" . "<a href=\"http://217.199.187.59/francoisle.fr/wdidy/activate=" . $key . "\">http://217.199.187.59/francoisle.fr/wdidy/activate=" . $key . "</a><br> <br><hr>" . "<i>This is an automatically generated email, please do not reply.</i><br> <br>" . "<b>The WDIDY Team</b>" . "</body></head></html>"; sendRegistrationMail($email, $sujet, $message); //mail($destinataire, $sujet, $message, $entete); // Envoi du mail echo "<script> swal({\n\t\t\t\t\t\t\t\t\t\ttitle:'Welcome :) !',\n\t\t\t\t\t\t\t\t\t\ttext:'You are going to receive an activation email',\n\t\t\t\t\t\t\t\t\t\ttype:'success'\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tfunction(){\n\t\t\t\t\t\t\t\t\t\t\twindow.location.href = 'index.php';\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t </script>"; } } } } } } // Header log si pas connecté (-1) if ($isConnect == -1) { include "header-log.php"; include "log.php"; include "body-log.php"; include "commit_history.php"; } else {
function registerUser() { global $db; $username = isset($_REQUEST["username"]) ? trim($_REQUEST["username"]) : ''; $password = isset($_REQUEST["password"]) ? trim($_REQUEST["password"]) : ''; $isemail = isset($_REQUEST["isemail"]) ? (bool) $_REQUEST["isemail"] : false; $languageid = isset($_REQUEST["languageid"]) ? trim($_REQUEST["languageid"]) : 'fr'; $firstname = isset($_REQUEST["firstname"]) ? trim($_REQUEST["firstname"]) : ''; $surname = isset($_REQUEST["surname"]) ? trim($_REQUEST["surname"]) : ''; $address = isset($_REQUEST["address"]) ? trim($_REQUEST["address"]) : ''; $zipcode = isset($_REQUEST["zipcode"]) ? trim($_REQUEST["zipcode"]) : ''; $city = isset($_REQUEST["city"]) ? trim($_REQUEST["city"]) : ''; $country = isset($_REQUEST["country"]) ? trim($_REQUEST["country"]) : ''; $sessionid = isset($_REQUEST["sessionid"]) ? (int) $_REQUEST["sessionid"] : 0; // <!-- registerUser(username="******", password="******", isemail="'.$isemail.'", languageid="'.$languageid.'", firstname="'.$firstname.'", surname="'.$surname.'", address="'.$address.'", zipcode="'.$zipcode.'", city="'.$city.'", country="'.$country.'")-->'; if ($username == '') { echoError(1); } else { $existingusers = pg_query($db, "SELECT username FROM \"user\" WHERE username = '******' LIMIT 1"); if (pg_num_rows($existingusers) > 0) { echoError(6, $username); } else { if ($password == '') { $password = generateRandomString(8); } pg_query($db, "BEGIN"); pg_query($db, "INSERT INTO \"user\" (username, password, isemail, languageid, firstname, surname, address, zipcode, city, country)\n VALUES ('" . pg_escape_string($username) . "',\n '" . pg_escape_string($password) . "',\n " . ($isemail == '' ? 'false' : 'true') . ",\n '" . pg_escape_string($languageid) . "',\n '" . pg_escape_string($firstname) . "',\n '" . pg_escape_string($surname) . "',\n '" . pg_escape_string($address) . "',\n '" . pg_escape_string($zipcode) . "',\n '" . pg_escape_string($city) . "',\n '" . pg_escape_string($country) . "')"); $userid = pg_fetch_result(pg_query($db, "SELECT MAX(id) AS id FROM \"user\""), 0, 'id'); pg_query($db, "COMMIT"); if ($userid == null || $userid == 0) { echoError(7); } else { if ($sessionid > 0) { setSessionUserDB($sessionid, $userid); } addUserPhotoDB($userid); if (sendRegistrationMail($userid)) { echoUser($userid); } } } } }