Example #1
0
    header('Location:' . WEB_PATH);
}
$userDao = new UserDao($em);
$roleDao = new RoleDao($em);
$error = null;
$info = null;
//save mode
if (isset($_POST['lastname']) && isset($_POST['firstname']) && isset($_POST['mail']) && isset($_POST['phone']) && isset($_POST['role']) && isset($_POST['company']) && isset($_POST['id']) && isset($_POST['state'])) {
    try {
        $user = $userDao->getByPrimaryKey($_POST['id']);
        if ($user == null) {
            $user = new User();
        }
        $user->setFirstName($_POST['firstname']);
        $user->setLastName($_POST['lastname']);
        $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()));