public function indexAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         return $this->_redirect('/');
     }
     // process the form
     $form = new Application_Form_Register();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 /**
                  * Check if a user with the given username or email already
                  * exists
                  */
                 $user_mapper = new Application_Model_UserMapper();
                 $user = $user_mapper->findByUsername($form->getValue('username'));
                 $email = $user_mapper->findByEmail($form->getValue('email'));
                 if (!$user && !$email) {
                     $values = $form->getValues();
                     $user_mapper = new Application_Model_UserMapper();
                     $user = new Application_Model_User($values);
                     // Hash the password with a random salt
                     $user->setPassword_salt(mcrypt_create_iv(64));
                     $user->setPassword_hash(hash('sha256', $user->getPassword_salt() . $form->getValue('password')));
                     $user->setActive(0);
                     // Insert the account into the database
                     $user_mapper->save($user);
                     $user = $user_mapper->findByUsername($user->getUsername());
                     if ($user) {
                         $user = $user[0];
                         // prompt the user to activate the account
                         $this->_helper->FlashMessenger('Successful Registration');
                         return $this->_redirect('/registration/confirm/id/' . $user->getId());
                     }
                 } else {
                     if ($user) {
                         print "A user with this user name already exists.";
                     }
                     if ($email) {
                         print "A user with this email already exists.";
                     }
                 }
             } else {
                 print "The password was not confirmed.";
             }
         } else {
             print 'Invalid form';
         }
     }
     $this->view->form = $form;
 }
Beispiel #2
0
 public function indexAction()
 {
     $form = new Application_Form_Register();
     $form->setMethod('POST');
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $values = $form->getValues();
         $users = $this->_helper->service('user')->findBy(array('email' => $values['email']));
         if (count($users) > 0) {
             $user = array_pop($users);
         } else {
             $user = $this->_helper->service('user')->createPending($values['email']);
         }
         if (!$user->isPending()) {
             $form->email->addError("User with email '{$values['email']}' is registered already.");
         } else {
             $this->_helper->service('email')->sendConfirmationToken($user);
             $this->_helper->redirector('after');
         }
     }
     $this->view->form = $form;
 }
 public function indexAction()
 {
     $translator = \Zend_Registry::get('container')->getService('translator');
     $form = new Application_Form_Register();
     $form->setMethod('POST');
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $values = $form->getValues();
         $users = $this->_helper->service('user')->findBy(array('email' => $values['email']));
         if (count($users) > 0) {
             $user = array_pop($users);
         } else {
             $publicationService = \Zend_Registry::get('container')->getService('newscoop_newscoop.publication_service');
             $user = $this->_helper->service('user')->createPending($values['email'], null, null, null, $publicationService->getPublication()->getId());
         }
         if (!$user->isPending()) {
             $form->email->addError(sprintf($translator->trans('User with email %s is registered already.', array(), 'users'), $values['email']));
         } else {
             $this->_helper->service('email')->sendConfirmationToken($user);
             $this->_helper->redirector('after');
         }
     }
     $this->view->form = $form;
 }
 public function registerAction()
 {
     // action body
     $this->view->page_title = "Registration Form";
     $user_form = new Application_Form_Register();
     if ($this->getRequest()->isPost()) {
         if ($user_form->isValid($_POST)) {
             $user_model = new Application_Model_User();
             $this->view->success = $user_model->addUser($user_form->getValues());
             $auth = Zend_Auth::getInstance();
             $namespace = new Zend_Session_Namespace();
             $namespace->username = $user_form->getValue('username');
             $namespace->password = $user_form->getValue('password');
             $namespace->id = $user_model->getID($namespace->username);
             $this->view->username = $namespace->username;
             $this->_redirect('/users/index');
         }
     }
     $this->view->form = $user_form;
 }