Example #1
0
 /**
  * @param UserEntity $user
  * @return ContactEntity|boolean
  */
 public function updateUser(UserEntity $user)
 {
     $contactEntity = $user->getContact();
     if ($contactEntity instanceof ContactEntity) {
         $contactEntity->setUser($user);
         // set modified user entity
         return $this->contactRepository->save(TRUE, $contactEntity);
     } else {
         return FALSE;
     }
 }
Example #2
0
 /**
  * @param array $data
  * @return ContactEntity|TRUE
  */
 public function register(array $data)
 {
     $contactEntity = new ContactEntity();
     $userEntity = new UserEntity();
     $contactEntity->setValues($data);
     $userEntity->setLogin($data['login']);
     $userEntity->setAclRoleID(10);
     // guest role
     $userEntity->setPassword($data['password']);
     $userEntity->setActive(TRUE);
     if (isset($data['lastLogged'])) {
         $userEntity->setLastLogged($data['lastLogged']);
     }
     if (isset($data['ip'])) {
         $userEntity->setIp($data['ip']);
     }
     $contactEntity->setUser($userEntity);
     $this->contactRepository->push($contactEntity);
     $result = $this->contactRepository->save();
     if ($result) {
         return $this->contactRepository->get($this->contactRepository->getLastInsertID());
     } else {
         return $result;
     }
 }
Example #3
0
 /** Submit
  * @param Form $form
  */
 public function Submit(Form $form)
 {
     $values = $form->getValues();
     $contactEntity = new ContactEntity();
     $userEntity = new UserEntity();
     $contactEntity->setValues((array) $values);
     $userEntity->setLogin($values->login);
     $userEntity->setAclRoleID(10);
     // guest role
     $userEntity->setPassword($values->password);
     $userEntity->setActive(TRUE);
     $contactEntity->setUser($userEntity);
     try {
         $this->contactRepository->push($contactEntity);
         $result = $this->contactRepository->save();
         if ($result) {
             $this->flashMessage("Vaše registrace proběhla úspěšně.");
             $this->redirect('this');
         } else {
             $form->addError("Vaše registrace neproběhla úspěšně.");
         }
     } catch (\PDOException $e) {
         if (strpos($e->getMessage(), "1062 Duplicate entry") !== FALSE) {
             $form->addError("Uživatel {$values->login} již existuje. Zvolte si prosím jiný přihlašovací email.");
         } else {
             $form->addError($e->getMessage());
         }
     }
 }
Example #4
0
 /**
  * @param Form $form
  */
 public function Submit(Form $form)
 {
     $json = new \stdClass();
     $json->result = "success";
     $values = $form->getValues();
     $result = false;
     if (!empty($values['userID'])) {
         $userEntity = $this->userRepository->get($values['userID']);
         if ($userEntity) {
             if ($this->user->isAllowed("user_management", "edit")) {
                 $userEntity->setLogin($values['login']);
                 if (!empty($values['password1'])) {
                     $userEntity->setPassword($values['password1']);
                 }
                 if ($userEntity->getLogin() !== "root" && $userEntity->getUserID() !== $this->user->getId()) {
                     $userEntity->setActive($values['active']);
                     if ($userEntity->getRole()->getAclRoleID() != $this->user->getIdentity()->data['aclRoleID']) {
                         $userEntity->setAclRoleID($values['role']);
                     }
                 }
                 try {
                     $result = $this->userRepository->save();
                 } catch (\PDOException $e) {
                     $result = $e->getMessage();
                 }
             } else {
                 $result = UserForm::PERMISSION;
             }
         }
     } else {
         if ($this->user->isAllowed("user_management", "add")) {
             $userEntity = new UserEntity();
             $userEntity->setLogin($values['login'])->setPassword($values['password1'])->setActive($values['active'])->setAclRoleID($values['role']);
             try {
                 $result = $this->userRepository->push($userEntity)->save();
             } catch (\PDOException $e) {
                 $result = $e->getMessage();
                 if (preg_match("/Duplicate entry/", $result)) {
                     $result = "Nick <strong>" . $values['login'] . "</strong> již existuje. Zvolte prosím jiný login.";
                 }
             }
             if ($result instanceof UserEntity || $result === TRUE) {
                 $result = TRUE;
             }
         } else {
             $result = UserForm::PERMISSION;
         }
     }
     if ($result === TRUE) {
         $json->result = "success";
     } else {
         $json->result = "error";
         $json->message = $result;
     }
     $response = new JsonResponse($json);
     $this->getPresenter()->sendResponse($response);
 }