public function registerAction() { $request = $this->getRequest(); $userRegisterForm = new UserRegisterForm(); if ($request->isPost()) { $user = new User(); $user->setUserLogin($request->getPost('user_login')); $user->setUserName($request->getPost('user_name')); $user->setUserEmail($request->getPost('user_email')); $user->setUserPassword(md5($request->getPost('user_password'))); $user->setUserIp($_SERVER['REMOTE_ADDR']); $user->setUserRegisterDate(new \DateTime('now')); $user->setUserProfile(1); $userRegisterForm->setInputFilter($user->getInputFilter()); $userRegisterForm->setData($request->getPost()); if ($userRegisterForm->isValid()) { $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); $this->flashMessenger()->addInfoMessage("Seu cadastrado foi realizado com sucesso, " . $request->getPost('user_name')); return $this->redirect()->toRoute('users-login'); } $this->flashMessenger()->addFlashMessage("Falha no Cadastro."); $this->redirect()->toRoute('users-login'); } return new ViewModel(array('userRegisterForm' => $userRegisterForm)); }
public function registerAction() { $request = $this->getRequest(); $form = new UserForm(); $userNameConflict = false; if ($request->isPost()) { // check if the form is valid $form->setData($request->getPost()); $form->setInputFilter(new UserInputFilter()); if ($form->isValid()) { $data = $form->getData(); $userRepo = $this->getObjectManager()->getRepository(User::class); $userNameConflict = $userRepo->findOneBy(['userName' => $data['username']]) instanceof User; if ($userNameConflict) { $form->get('username')->setValue(''); } else { // if the requested username is not taken yet, create the password and redirect the user to the login $user = new User(); $user->setEmail($data['email']); $user->setUserName($data['username']); $bcrypt = new Bcrypt(); $password = $bcrypt->create($data['password']); $user->setPassword($password); $this->getObjectManager()->persist($user); $this->getObjectManager()->flush(); return $this->redirect()->toRoute('application/user', ['action' => 'login']); } } } return new ViewModel(['form' => $form, 'userNameConflict' => $userNameConflict]); }
/** * {@inheritDoc} */ public function setUserName($userName) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUserName', array($userName)); return parent::setUserName($userName); }