Ejemplo 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);
         }
     }
 }
Ejemplo n.º 2
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"];
             }
         }
     }
 }
Ejemplo n.º 3
0
 function editFamilyMember()
 {
     if (isset($_POST["UserId"]) && isset($_POST["UserName"]) && isset($_POST["UserInfoFirstName"]) && isset($_POST["UserInfoLastName"]) && isset($_POST["UserInfoTel"])) {
         //TODO: Verif si email déjà en utilisation, si oui alors modification annulé
         Users::updateFirstLastName($_POST["UserId"], $_POST["UserInfoFirstName"], $_POST["UserInfoLastName"]);
         Users::updateTel($_POST["UserId"], $_POST["UserInfoTel"]);
         Users::updateUserName($_POST["UserId"], $_POST["UserName"]);
         $user = Users::getUser($_POST["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);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 function generateFullReport()
 {
     $objectId = $_POST["object"];
     $objects = Objects::getAllVisibleObjectsInContainer($objectId, $_SESSION["id"]);
     $toRender = array();
     $done = false;
     $level = 0;
     $levelstack = array(count($objects));
     $sum = Objects::getObjectValue($objectId);
     while (!$done) {
         if (count($objects) > 0) {
             $levelstack[$level]--;
             $object = array_pop($objects);
             /*$object["ObjectContentValue"] = Objects::getVisibleObjectContentValue($object["ObjectId"],$_SESSION["id"]);
               $object["ObjectTotalValue"] = ($object["ObjectInitialValue"]+$object["ObjectContentValue"]) * $object["ObjectQuantity"];*/
             $object["ObjectTotalValue"] = $object["ObjectInitialValue"] * $object["ObjectQuantity"];
             if (isset($object["quantity"])) {
                 $object["quantity"] = $object["ObjectQuantity"] * $object["quantity"];
             } else {
                 $object["quantity"] = $object["ObjectQuantity"];
             }
             $object["level"] = $level * 25;
             //Effectuer l'opération sur l'objet en cours
             array_push($toRender, $object);
             $sum += $object["ObjectInitialValue"] * $object["quantity"];
             //Charger l'objet suivant
             if (Objects::isObjectContainer($object["ObjectId"])) {
                 $level++;
                 $objectsInContainer = Objects::getAllVisibleObjectsInContainer($object["ObjectId"], $_SESSION["id"]);
                 foreach ($objectsInContainer as $objectToAdd) {
                     $objectToAdd["quantity"] = $object["quantity"];
                     array_push($objects, $objectToAdd);
                 }
                 $levelstack[$level] = count($objectsInContainer);
             }
             while ($levelstack[$level] == 0 && $level > 0) {
                 $level--;
             }
         } else {
             $done = true;
         }
     }
     $container = Objects::getObject($objectId);
     $user = Users::getUser($_SESSION["id"]);
     $data = array("containerValue" => Objects::getObjectValue($objectId), "name" => $user["UserInfoFirstName"] . " " . $user["UserInfoLastName"], "date" => date("Y-m-j"), "objects" => $toRender, "total" => (Objects::getVisibleObjectContentValue($objectId, $_SESSION["id"]) + Objects::getObjectValue($objectId)) * Objects::getObjectQuantity($objectId), "container" => $container["ObjectName"], "containerId" => $container["ObjectId"], "containerQuantity" => $container["ObjectQuantity"]);
     $this->renderTemplate(file_get_contents("public/html/fullreport.html"), $data);
 }
Ejemplo n.º 6
0
 function getFamilyOwner()
 {
     if (isset($_POST["familyOwnerId"])) {
         echo json_encode(Users::getUser($_POST["familyOwnerId"]));
     }
 }