Esempio n. 1
0
 function register()
 {
     if ('POST' == $_SERVER['REQUEST_METHOD']) {
         //stocke les valeurs
         $email = strtolower($_POST["txtMail"]);
         $firstName = $_POST["txtFirstName"];
         $lastName = $_POST["txtLastName"];
         $phone = $_POST["txtPhone"];
         $pass = $_POST["txtPassword"];
         $passCheck = $_POST["txtPasswordConfirm"];
         if (!empty($_POST["txtMail"]) and !empty($_POST["txtFirstName"]) and !empty($_POST["txtLastName"]) and !empty($_POST["txtPhone"]) and !empty($_POST["txtPassword"])) {
             //modifier le numéro de téléphone afin de correspondre à la BD
             $phone = self::normalizePhoneNumber($phone);
             //vérifier si informations valides (email + pass)
             if (Users::getUserIdByName($email) == -1 && $pass == $passCheck) {
                 $salt = self::generateSalt();
                 $crypt = crypt($pass, $salt);
                 $userId = Users::addFamilyOwner($email, $phone, $firstName, $lastName, $crypt, $salt);
                 $owner = $userId;
                 $name = "Contenant principal";
                 $parent = null;
                 $value = 0;
                 $initValue = 0;
                 $warranty = "";
                 $infos = "";
                 $summary = "Contenant de départ";
                 $public = 1;
                 $quantity = 1;
                 Objects::addObject($name, $owner, $parent, $value, $initValue, $warranty, $infos, $summary, $public, $quantity);
                 header(CONNECTION_HEADER . '/registration');
                 if (isset($userId)) {
                     $user = Users::getUser($userId);
                     $headers = 'MIME-Version: 1.0' . "\r\n";
                     $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                     $to = "";
                     $recipients = Users::getAllAdminMail();
                     foreach ($recipients as $recipient) {
                         $to .= $recipient . ', ';
                     }
                     substr($to, 0, -2);
                     $subject = "Nouvelle demande de patrimoine";
                     $data = array('path' => SERVER_ABSOLUTE_PATH . "/sysadmin", 'user' => $user["UserName"], 'img' => PUBLIC_ABSOLUTE_PATH . "/assets/logo_petit.png");
                     $mustache = new Mustache_Engine();
                     mail($to, $subject, $mustache->render(file_get_contents('public/html/mailtemplateregistration.html'), $data), $headers . "From: " . SENDING_EMAIL);
                 }
             } else {
                 $data = array("SERVER_ABSOLUTE_PATH" => SERVER_ABSOLUTE_PATH, "PUBLIC_ABSOLUTE_PATH" => PUBLIC_ABSOLUTE_PATH, "Error" => true, "ErrorMSG" => Users::getUserIdByName($email) != -1 ? "Adresse courriel déjà en utilisation" : "Vous devez saisir le même mot de passe", "FirstName" => $firstName, "LastName" => $lastName, "Phone" => $phone, "Email" => $email);
                 $this->renderTemplate(file_get_contents(REGISTRATION_PAGE), $data);
             }
         } else {
             $data = array("SERVER_ABSOLUTE_PATH" => SERVER_ABSOLUTE_PATH, "PUBLIC_ABSOLUTE_PATH" => PUBLIC_ABSOLUTE_PATH, "Error" => true, "ErrorMSG" => "Informations manquantes", "FirstName" => $firstName, "LastName" => $lastName, "Phone" => $phone, "Email" => $email);
             $this->renderTemplate(file_get_contents(REGISTRATION_PAGE), $data);
         }
     }
 }
Esempio n. 2
0
 function addFamilyMember()
 {
     if (isset($_POST["UserName"]) && isset($_POST["UserPass"]) && isset($_POST["UserInfoTel"]) && isset($_POST["UserInfoFirstName"]) && isset($_POST["UserInfoLastName"])) {
         if (Users::isUserExistByMail($_POST["UserName"])) {
             echo json_encode(array("errors" => array("L'adresse de courriel que vous avez fournie est déjà utilisé")));
         } else {
             $salt = Registration::generateSalt();
             $crypt = crypt($_POST["UserPass"], $salt);
             $ownerId = Users::getFamilyOwnerByUserId($_SESSION["id"]);
             Users::addUser($_POST["UserName"], $_POST["UserInfoTel"], $_POST["UserInfoFirstName"], $_POST["UserInfoLastName"], $ownerId[0][0], $crypt, $salt);
             $userId = Users::getUserIdByName($_POST["UserName"]);
             $user = Users::getUser($userId);
             $phoneNumber = $user["UserInfoTel"];
             $phoneNumber = Registration::normalizePhoneNumber($phoneNumber);
             $user["UserInfoTel"] = $phoneNumber[0] . " (" . mb_substr($phoneNumber, 1, 3) . ") " . mb_substr($phoneNumber, 4, 3) . "-" . mb_substr($phoneNumber, 7, 4);
             echo json_encode($user);
         }
     }
 }
Esempio n. 3
0
 function login()
 {
     if (isset($_POST["Password"]) && isset($_POST["Email"])) {
         $userId = Users::getUserIdByName($_POST["Email"]);
         if ($userId != -1) {
             $user = Users::getUser($userId);
             if (crypt($_POST["Password"], $user["UserSalt"]) == $user["UserHash"]) {
                 $token = self::generateToken();
                 Users::setUserMobileToken($userId, $token);
                 echo $token;
             }
         }
     } else {
         if (isset($_POST["Token"]) && $_POST["Token"] != null) {
             $userId = Users::getUserIdByMobileToken($_POST["Token"]);
             if ($userId != -1) {
                 echo $_POST["Token"];
             }
         }
     }
 }
Esempio n. 4
0
 function forgot()
 {
     $userId = Users::getUserIdByName($_POST["txtUserNameForgot"]);
     if ($userId != -1) {
         $code = self::generateCode(16);
         Users::addCode($userId, $code);
         $headers = 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
         $subject = "Réinitialisation de votre mot de passe";
         $data = array('passwordResetLink' => SERVER_ABSOLUTE_PATH . "/passwordreset", 'code' => $code, 'img' => PUBLIC_ABSOLUTE_PATH . "/assets/favicons/android-icon-192x192.png");
         $mustache = new Mustache_Engine();
         mail($_POST["txtUserNameForgot"], $subject, $mustache->render(file_get_contents('public/html/mailtemplate.html'), $data), $headers . "From: " . SENDING_EMAIL);
     }
     $data = array("Forgot" => true);
     $this->renderTemplate(file_get_contents(CONNECTION_PAGE), $data);
 }