コード例 #1
0
ファイル: AuthController.php プロジェクト: hopealive/ds
 public function registerAction()
 {
     $form = new \Application\Form\RegisterForm();
     $request = $this->getRequest();
     $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     $adapter = $authService->getAdapter();
     $data = array();
     $model = new User();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         $model->setEmail($request->getPost()->email);
         $model->setName($request->getPost()->name);
         $model->setRole(User::UserRoleRegisteredUser);
         if (!empty($request->getPost()->password)) {
             $model->setPassword($request->getPost()->password);
         }
         if ($form->isValid()) {
             $this->getObjectManager()->persist($model);
             $this->getObjectManager()->flush();
             //                return $this->redirect()->toUrl('/admin/' . $this->_modelAlias);
         }
     }
     $viewVariables['form'] = $form;
     $viewVariables['model'] = $model;
     //        $this->_view->setVariables($viewVariables);
     return new ViewModel($viewVariables);
 }
コード例 #2
0
ファイル: UserController.php プロジェクト: spoorey/hangman
 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]);
 }
コード例 #3
0
ファイル: LoadUserData.php プロジェクト: mdb-webdev/zfb2
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('testuser');
     $user->setPassword('test123');
     $user->setEmail('*****@*****.**');
     $manager->persist($user);
     $manager->flush();
 }
コード例 #4
0
ファイル: RegisterController.php プロジェクト: jkhaled/docdz
 /**
  * validate data and register user in DB
  *
  * @return ViewModel
  */
 public function processAction()
 {
     if ($this->request->isPost()) {
         $form = new RegisterForm();
         $data = $this->params()->fromPost();
         $viewModel = new ViewModel();
         $viewModel->setTemplate('user/register/index');
         $viewModel->setVariable("registerForm", $form);
         $form->setData($data);
         if ($form->isValid()) {
             if ($data["password"] == $data["confirm_password"]) {
                 $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
                 $user = $em->getRepository('Application\\Entity\\User')->findByEmail($data['email']);
                 if ($user) {
                     $viewModel->setVariable('accountExistError', true);
                     return $viewModel;
                 }
                 $user = new User();
                 $user->setFirstname($data['firstname']);
                 $user->setLastname($data['lastname']);
                 $user->setEmail($data['email']);
                 $user->setPhone($data['phone']);
                 $user->setPassword($data['password']);
                 $user->setGender($data['gender']);
                 $user->setBlocked(0);
                 $user->setEmailVerified(0);
                 $user->setPhoneVerified(0);
                 $user->setBanned(0);
                 $user->setRole('u');
                 $user->setExperience(0);
                 $user->setBirthYear($data['birthyear']);
                 $user->setRegistredDate(time());
                 $em->persist($user);
                 $em->flush();
                 $params = ["email" => $user->getEmail()];
                 //$eventManager = $this->getEventManager()->trigger('sendMail', null, );
                 //TODO continue and send mail by Listener class
                 $this->redirect()->toRoute('user', ['controller' => 'register', 'action' => 'success']);
             } else {
                 $viewModel->setVariable('passwordError', true);
                 return $viewModel;
             }
         } else {
             $viewModel->setVariable('formError', true);
             return $viewModel;
         }
     } else {
         $this->redirect()->toRoute('user', ['controller' => "register", "action" => "index"]);
     }
 }
コード例 #5
0
 public function registrationAction()
 {
     $userRegForm = new UserRegistrationForm($this->getEntityManager());
     $userRegForm->getInputFilter()->remove('roles');
     $userRegForm->get('submit')->setValue('Sign Up');
     $userRegForm->setAttribute('action', '/user/registration')->prepare();
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return new ViewModel(array('userRegForm' => $userRegForm));
     }
     $userFormData = $request->getPost();
     $userRegForm->setData($userFormData);
     if (!$userRegForm->isValid()) {
         return new ViewModel(array('userRegForm' => $userRegForm));
     }
     $entityManager = $this->getEntityManager();
     $email = $entityManager->getRepository('Application\\Entity\\User')->findOneByEmail($userFormData['user']['email']);
     if (!empty($email)) {
         $this->flashmessenger()->addMessage('Email already exist.');
         return new ViewModel(array('userRegForm' => $userRegForm, 'messages' => $this->flashmessenger()->getMessages()));
     }
     $userEntity = new UserEntity();
     $userEntity->setEmail($userFormData['user']['email']);
     $userEntity->setPassword($userFormData['user']['password']);
     $userEntity->setCreatedAt();
     $userEntity->setUpdatedAt();
     $userEntity->addRole($entityManager->getRepository('Application\\Entity\\Role')->findOneById($userFormData['roles']['roles']));
     $entityManager->persist($userEntity);
     $entityManager->flush();
     $userProfileEntity = new UserProfileEntity();
     $userProfileEntity->setFirstName($userFormData['profile']['firstname']);
     $userProfileEntity->setLastName($userFormData['profile']['lastname']);
     $userProfileEntity->setPhone($userFormData['profile']['phone']);
     $userProfileEntity->setWebsite($userFormData['profile']['website']);
     $userProfileEntity->setBirthdate(new \DateTime($userFormData['profile']['birthdate']));
     $userProfileEntity->setUser($userEntity);
     $userProfileEntity->setCreatedAt();
     $userProfileEntity->setUpdatedAt();
     $entityManager->persist($userProfileEntity);
     $entityManager->flush();
     $entityManager->clear();
     return new ViewModel(array('userRegForm' => $userRegForm, 'messages' => $this->flashmessenger()->getMessages()));
 }
コード例 #6
0
 public function saveUserAction()
 {
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $data = $this->getRequest()->getPost();
     $user = new User();
     $user->setUsername(strip_tags($data['player_name']));
     $user->setPassword(md5($data['player_password']));
     $user->setMail(strip_tags($data['player_email']));
     $user->setColor(strip_tags($data['player_color']));
     $em->persist($user);
     $em->flush();
     $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     $adapter = $authService->getAdapter();
     $adapter->setIdentityValue(strip_tags($data['player_name']));
     $adapter->setCredentialValue(md5($data['player_password']));
     $authResult = $authService->authenticate();
     if ($authResult->isValid()) {
         return $this->redirect()->toRoute('game');
     }
     return $this->redirect()->toRoute('home');
 }
コード例 #7
0
ファイル: UserController.php プロジェクト: hopealive/ds
 public function editAction()
 {
     $form = new \Admin\Form\UserForm();
     $id = (int) $this->params()->fromRoute('id', 0);
     if ($id > 0) {
         $model = $this->getObjectManager()->find($this->_modelName, $id);
         $form->setData($model->toArray());
         $form->setAttribute('action', '/admin/' . $this->_modelAlias . '/edit/' . $id);
         $form->get('submit')->setAttribute('value', 'Edit');
         $model->setUpdatedDate(new \DateTime());
         $viewVariables['action'] = 'Edit';
     } else {
         $model = new User();
         $form->setAttribute('action', '/admin/' . $this->_modelAlias . '/add');
         $form->get('submit')->setAttribute('value', 'Add');
         $model->setCreatedDate(new \DateTime());
         $viewVariables['action'] = 'Add';
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         $model->setEmail($request->getPost()->email);
         $model->setName($request->getPost()->name);
         $model->setRole($request->getPost()->role);
         if (!empty($request->getPost()->password)) {
             $model->setPassword($request->getPost()->password);
         }
         if ($form->isValid()) {
             $this->getObjectManager()->persist($model);
             $this->getObjectManager()->flush();
             return $this->redirect()->toUrl('/admin/' . $this->_modelAlias);
         }
     }
     $viewVariables['form'] = $form;
     $viewVariables['model'] = $model;
     $this->_view->setTemplate('admin/' . $this->_modelAlias . '/edit');
     $this->_view->setVariables($viewVariables);
     return $this->_view;
 }
コード例 #8
0
 public function addAction()
 {
     $form = new UserForm();
     $request = $this->getRequest();
     $userDAO = UserDAO::getInstance($this->getServiceLocator());
     if ($request->isPost()) {
         $post = $request->getPost()->toArray();
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $userData = new User();
             $userData->setDisplayName($data['displayName']);
             $userData->setEmail($data['email']);
             $userData->setPassword(md5($data['password']));
             $userData->setRole(RoleDAO::getInstance($this->getServiceLocator())->findOneById($data['role']));
             $userDAO->save($userData);
             return $this->redirect()->toRoute('users');
         } else {
             $form->getMessages();
         }
     }
     return array('form' => $form);
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  */
 public function setPassword($password)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPassword', array($password));
     return parent::setPassword($password);
 }
コード例 #10
0
 /**
  * Register new User
  * @return array
  */
 public function registerAction()
 {
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('registerForm');
     $form->setInputFilter(new Form\RegisterFilter($this->getObjectManager()));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //CREATE NEW USER
             $user = new User();
             $user->setCompany($this->getRequest()->getPost('company'));
             $user->setFirstName($this->getRequest()->getPost('first_name'));
             $user->setLastName($this->getRequest()->getPost('last_name'));
             $user->setEmail($this->getRequest()->getPost('email'));
             $bcrypt = new Bcrypt();
             $securePass = $bcrypt->create($this->getRequest()->getPost('password'));
             $user->setPassword($securePass);
             $user->setStatus(0);
             $token = md5(uniqid(mt_rand(), true));
             $user->setToken($token);
             $user->setAddress("");
             $user->setZipcode("");
             $user->setCity("");
             $user->setCountry("");
             $user->setPhone("");
             $user->setCreated(new \DateTime("now"));
             $user->setLastModified(new \DateTime("now"));
             //AND SAVE USER TO DB
             $this->getObjectManager()->persist($user);
             $this->getObjectManager()->flush();
             // $newId = $user->getId();
             //COMPOSE AND SEND ACTIVATION MAIL
             //@TODO move hostname/baseurl to config
             $url = "http://www.example.net/login?token=" . $token;
             $translator = $this->getServiceLocator()->get('translator');
             //Create text part of mail
             $textContent = sprintf($translator->translate("registration_mail_text"), $url);
             $text = new MimePart($textContent);
             $text->type = "text/plain";
             //Create html part of mail
             $htmlMarkup = sprintf($translator->translate("registration_mail_html"), $url);
             $html = new MimePart($htmlMarkup);
             $html->type = "text/html";
             //Compose mail
             $body = new MimeMessage();
             $body->setParts(array($text, $html));
             $message = new Message();
             //@TODO move email address etc. to config
             $message->addFrom("*****@*****.**", "example.net")->addTo($user->getEmail(), $user->getFirstName() . " " . $user->getLastName())->setSubject($translator->translate("registration_mail_subject"));
             $message->setBody($body);
             $message->setEncoding("UTF-8");
             //Debug mail: echo $message->toString();
             //Depending on how you send mail..
             /*$transport = new SmtpTransport();
             		$options   = new SmtpOptions(array(
                			'name'              => 'localhost.localdomain',
                			'host'              => '127.0.0.1',
                			'connection_class'  => 'login',
                			'connection_config' => array(
                    			'username' => 'user',
                    			'password' => 'pass',
                			),
             		));
             		$transport->setOptions($options);*/
             //Send email
             $transport = new SendmailTransport();
             $transport->send($message);
             //REDIRECT TO SENT-PAGE
             return $this->redirect()->toRoute('home');
         }
     }
     return array('form' => $form);
 }