Exemplo n.º 1
0
 public function createAction()
 {
     $userForm = new UserForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $userForm->setInputFilter(new UserFilter());
         $userForm->setData($request->getPost());
         if ($userForm->isValid()) {
             $entityManager = $this->getEntityManager();
             $data = $userForm->getData();
             $user = new User();
             $pass = UserService::encryptPassword($data['user_password']);
             $user->setUserName($data['user_name'])->setUserPassword($pass['password'])->setUserPasswordSalt($pass['password_salt'])->setUserActive(true);
             $entityManager->persist($user);
             $entityManager->flush();
             return $this->redirect()->toRoute('authentication/user', array('action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $userForm));
 }
Exemplo n.º 2
0
 /**
  * Busca pelo usuário da inscrição $id. Caso não exista cria um novo.
  * 
  * @param Person $person pessoa associada à inscrição
  * @return User
  */
 protected function getUserIfExistsCreateIfNotExists(Person $person)
 {
     $em = $this->getEntityManager();
     // se não possui usuário
     if ($person->getUser() === null) {
         $user = new User();
         $userName = $person->getPersonEmail();
         $userPassword = preg_replace('/[.,-]/', '', $person->getPersonCpf());
         $pass = UserService::encryptPassword($userPassword);
         $user->setUserName($userName)->setUserPassword($pass['password'])->setUserPasswordSalt($pass['password_salt'])->setUserActive(true);
         $person->setUser($user);
         $em->merge($person);
         return $user;
     }
     return $person->getUser();
 }