/**
  * check credential and authenticate user
  * @param $login
  * @param $password
  * @return User
  */
 public function authentificate($login, $password)
 {
     $userDao = new UserDao(self::$em);
     $user = $userDao->getUserByMail($login);
     //        var_dump($user);
     //        var_dump(self::hashPassword($password, $user->getSalt()));
     if ($user != null && $user->getPassword() === self::hashPassword($password, $user->getSalt()) && $user->getStatus() == 1) {
         $user->setSession(session_id());
         $userDao->save($user);
         $_SESSION['auth'] = session_id();
         return $user;
     } else {
         return null;
     }
 }
Beispiel #2
0
/*-----------------------------------------------------*/
use MealBooker\manager\MailManager;
use MealBooker\manager\SecurityManager;
use MealBooker\model\User;
use MealBooker\models\dao\CompanyDao;
use MealBooker\models\dao\RoleDao;
use MealBooker\models\dao\UserDao;
use MealBooker\utils\Utils;
$error = null;
$info = null;
if (isset($_POST) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['firstName']) && isset($_POST['lastName']) && isset($_POST['idEntreprise']) && isset($_POST['password']) && isset($_POST['passwordCheck'])) {
    $companyDao = new CompanyDao($em);
    $userDao = new UserDao($em);
    $roleDao = new RoleDao($em);
    try {
        if ($userDao->getUserByMail($_POST['email']) != null) {
            throw new Exception("Ce mail est déjà utilisé par un compte existant");
        }
        //set user data
        $user = new User();
        $user->setLastName($_POST['lastName']);
        $user->setFirstName($_POST['firstName']);
        $user->setMail($_POST['email']);
        $user->setPhoneNumber($_POST['phone']);
        //check password validation
        if ($_POST['password'] != $_POST['passwordCheck']) {
            throw new Exception("Le champs mot de passe et confirmation mot de passe doivent étre identiques");
        }
        $user->setPassword(password_hash($_POST['password'], PASSWORD_BCRYPT, ['salt' => $user->getSalt()]));
        //set user role to user
        $role = $roleDao->getByPrimaryKey('2');
/*     | | \ \  __/ (__| |_| |_| \__ \  / /_   / /     */
/*     |_|  \_\___|\___|\__|\__,_|___/ |____| /_/      */
/*                                                     */
/*                Date: 23/09/2015                     */
/*                 All right reserved                  */
/*-----------------------------------------------------*/
use MealBooker\manager\MailManager;
use MealBooker\manager\SecurityManager;
use MealBooker\models\dao\UserDao;
$mod = "QUERY";
if (isset($_POST['email']) && sizeof($_POST['email']) > 0) {
    //query token
    try {
        $email = $_POST['email'];
        $userDao = new UserDao($em);
        $user = $userDao->getUserByMail($email);
        if ($user == null) {
            throw new Exception("Adresse Email inconnue");
        } else {
            $user->setRestoreToken(\MealBooker\utils\Utils::generateStringCode());
            $userDao->save($user);
            MailManager::get()->sendRestorePasswordMail($user);
            $message = 'Un E-mail vous a été envoyé pour réaliser la restauration de votre mot de passe';
        }
    } catch (Exception $ex) {
        $error = $ex->getMessage();
    }
} else {
    if (isset($_POST['restorepassword']) && sizeof($_POST['restorepassword']) > 0 && isset($_POST['token']) && sizeof($_POST['token']) > 0) {
        //token and new password validation
        try {