Ejemplo n.º 1
0
 /**
  * @param $fields
  * @return bool
  */
 public function signupValidation($fields = array())
 {
     $errors = null;
     if (isset($fields->name) && $this->applyValidationRules('notEmpty', $fields->name) == false) {
         $errors['name'] = 'Name must be required';
     }
     if (isset($fields->email) && $this->applyValidationRules('notEmpty', $fields->email) == false) {
         $errors['email'] = 'Email must be required';
     }
     if (isset($fields->email) && $this->applyValidationRules('email', $fields->email) == false) {
         $errors['email'] = 'Please provide valid email address';
     }
     if (isset($fields->email) && !isset($errors['email'])) {
         $user = new Users();
         $isExist = $user->whereEmail($fields->email)->first();
         if ($isExist) {
             $errors['email'] = 'This email is already taken';
         }
     }
     if (isset($fields->password) && $this->applyValidationRules('notEmpty', $fields->password) == false) {
         $errors['password'] = '******';
     }
     if (isset($fields->cPassword) && $this->applyValidationRules('notEmpty', $fields->cPassword) == false) {
         $errors['cPassword'] = '******';
     }
     if (isset($fields->cPassword) && $this->applyValidationRules('matchPassword', $fields->cPassword, $fields) == false) {
         $errors['cPassword'] = '******';
     }
     return $errors;
     /**
      * TODO validation script should write in proper way
      */
 }
Ejemplo n.º 2
0
 function resetpassword()
 {
     $userId = Users::getUserIdByCode($_POST["txtCode"]);
     if ($userId != -1) {
         $date = Users::getCodeDate($_POST["txtCode"]);
         $date = strtotime($date) + 600;
         if (strtotime(date("Y-m-d H:i:s")) <= $date) {
             if ($_POST["txtPassword"] == $_POST["txtPasswordConfirm"]) {
                 $salt = Registration::generateSalt();
                 $crypt = crypt($_POST["txtPassword"], $salt);
                 Users::updatePassword($userId, $crypt, $salt);
                 Users::deleteCode($userId);
                 header(CONNECTION_HEADER);
             }
         } else {
             Users::deleteCode($userId);
             $data = array("Forgot" => true);
             $this->renderTemplate(file_get_contents(RESET_PAGE), $data);
         }
     } else {
         Users::deleteCode($userId);
         $data = array("Forgot" => true);
         $this->renderTemplate(file_get_contents(RESET_PAGE), $data);
     }
 }
Ejemplo n.º 3
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.º 4
0
 public function handleDeleteUser($user_id)
 {
     $this->onBeforeRestrictedFunctionality($this);
     try {
         $this->users->delete($this->users->findOneBy(['id' => $user_id]));
         $this->flashMessage('Uživatel byl úspěšně smazán.', 'success');
     } catch (\Exception $exc) {
         $this->flashMessage($exc->getMessage(), 'danger');
     }
     $this->redirect('this');
 }
Ejemplo n.º 5
0
 function objects()
 {
     if (isset($_POST["Token"]) && isset($_POST["ObjectId"]) && $_POST["Token"] != null) {
         $userId = Users::getUserIdByMobileToken($_POST["Token"]);
         if ($userId != -1) {
             if ($_POST["ObjectId"] == null) {
                 $object = new stdClass();
                 $object->CurrentObject = null;
                 $object->ParentObject = null;
                 $object->ChildObjects = Objects::getAllVisibleObjectsInContainer(null, $userId);
                 echo JSON_ENCODE($object);
             } else {
                 $object = new stdClass();
                 $object->CurrentObject = Objects::getObject($_POST["ObjectId"]);
                 $object->ParentObject = $object->CurrentObject["ObjectContainer"] == null ? null : Objects::getObject($object->CurrentObject["ObjectContainer"]);
                 $object->ChildObjects = Objects::getAllVisibleObjectsInContainer($_POST["ObjectId"], $userId);
                 echo JSON_ENCODE($object);
             }
         }
     }
 }
Ejemplo n.º 6
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.º 7
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);
 }
Ejemplo n.º 8
0
<?php

use Model\Users;
$app->post('/users', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $user->uuid = \Lib\App::v4();
    $user->name = $data->name;
    $user->email = $data->email;
    $user->password = password_hash($data->password, PASSWORD_BCRYPT);
    $user->save();
    echo json_encode($data);
});
$app->post('/users/login', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $result = $user->where('email', $data->email)->first();
    echo json_encode($result);
});
$app->post('/users/is_email_unique', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $isExist = $user->whereEmail($data->email)->first();
    echo json_encode($isExist);
});
Ejemplo n.º 9
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.º 10
0
<?php

/**
 * Created by PhpStorm.
 * User: TaF
 * Date: 11/12/2015
 * Time: 13:32
 */
use Model\Users;
use Touffik\Query;
require_once 'vendor/autoload.php';
$user = new Users();
$user->setName('Titi');
$user->setEmail('*****@*****.**');
$user->setPassword('test');
$user->save();
////$user = new Users();
//var_dump($user);
$userQuery = new Query();
$userQuery->find('users');
Ejemplo n.º 11
0
 function getFamilyOwner()
 {
     if (isset($_POST["familyOwnerId"])) {
         echo json_encode(Users::getUser($_POST["familyOwnerId"]));
     }
 }