Example #1
0
        $user->setMail($_POST['mail']);
        $user->setPhoneNumber($_POST['phone']);
        $user->setOptIn(isset($_POST['optin']) ? true : false);
        $user->setStatus($_POST['state']);
        $role = $roleDao->getByPrimaryKey($_POST['role']);
        if ($role == null) {
            throw new Exception("une erreur est survenue -> 0x1");
        }
        $user->setRole($role);
        $user->setCompany($_POST['company']);
        //if already password save
        if (isset($_POST['password']) && strlen($_POST['password']) > 0) {
            if ($_POST['password'] != $_POST['passwordchk']) {
                throw new Exception("Le champs mot de passe et confirmation mot de passe doivent étre identiques");
            }
            $user->setPassword(SecurityManager::get()->hashPassword($_POST['password'], $user->getSalt()));
        } else {
            if ($user->getPassword() == null && strlen($_POST['password']) < 1) {
                throw new Exception("un mot de passe est requis");
            }
        }
        $userDao->save($user);
        header('Location:' . WEB_PATH . '?page=admin&tab=users');
    } catch (Exception $ex) {
        echo $error;
        $error = $ex->getMessage();
    }
}
//view Mode
if (isset($_GET['id'])) {
    $user = $userDao->getByPrimaryKey($_GET['id']);
Example #2
0
 $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');
     if ($role == null) {
         throw new Exception("une erreur est survenue");
     }
     $user->setRole($role);
     //set company with validation code
     $company = $companyDao->getByValidationCode($_POST['idEntreprise']);
     if ($company == null) {
         throw new Exception("Code de validation inconnu");
     }
     $user->setCompany($company);
     //set optIn
     if (isset($_POST['optIn'])) {
         $user->setOptIn($_POST['optIn']);