コード例 #1
0
 public function editAction()
 {
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('authentication/user', array('action' => 'index'));
     }
     $entityManager = $this->getEntityManager();
     try {
         $user = $entityManager->getReference('Authentication\\Entity\\User', $id);
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
     $form = new UserForm();
     $form->get('user_name')->setValue($user->getUserName());
     $request = $this->getRequest();
     if ($request->isPost()) {
         $formFilter = new UserFilter();
         $formFilter->get('user_name')->setRequired(false);
         $form->setInputFilter($formFilter);
         $data = $request->getPost();
         $form->setData($data);
         $form->get('user_name')->setValue($user->getUserName());
         if ($form->isValid()) {
             $pass = UserService::encryptPassword($data['user_password']);
             $user->setUserPassword($pass['password'])->setUserPasswordSalt($pass['password_salt']);
             $entityManager->persist($user);
             $entityManager->flush();
             return $this->redirect()->toRoute('authentication/user', array('action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
コード例 #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();
 }