예제 #1
0
 public function confirmAction()
 {
     $user = $this->_helper->service('user')->find($this->_getParam('user'));
     if (empty($user)) {
         $this->_helper->flashMessenger(array('error', "User not found"));
         $this->_helper->redirector('index', 'index', 'default');
     }
     if (!$user->isPending()) {
         $this->_helper->flashMessenger(array('error', "User has been activated"));
         $this->_helper->redirector('index', 'index', 'default');
     }
     $token = $this->_getParam('token', false);
     if (!$token) {
         $this->_helper->flashMessenger(array('error', "No token provided"));
         $this->_helper->redirector('index', 'index', 'default');
     }
     if (!$this->_helper->service('user.token')->checkToken($user, $token, 'email.confirm')) {
         $this->_helper->flashMessenger(array('error', "Invalid token"));
         $this->_helper->redirector('index', 'index', 'default');
     }
     $form = new Application_Form_Confirm();
     $form->setMethod('POST');
     $values = array();
     if ($user->getFirstName()) {
         $values['first_name'] = $user->getFirstName();
     }
     if ($user->getLastName()) {
         $values['last_name'] = $user->getLastName();
     }
     $form->populate($values);
     $this->view->terms = false;
     if ($user->getFirstName() || $user->getLastName()) {
         $form->addElement('checkbox', 'terms_of_use', array('label' => 'Accepting terms of use', 'required' => true, 'validators' => array(array('greaterThan', true, array('min' => 0))), 'errorMessages' => array("Sie können sich nur registrieren, wenn Sie unseren Nutzungsbedingungen zustimmen. Dies geschieht zu Ihrer und unserer Sicherheit. Bitten setzen Sie im entsprechenden Feld ein Häkchen.")));
         $this->view->terms = true;
     }
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         try {
             $values = $form->getValues();
             $this->_helper->service('user')->savePending($values, $user);
             $this->_helper->service('user.token')->invalidateTokens($user, 'email.confirm');
             $this->_helper->service('dispatcher')->notify('user.register', new GenericEvent($this, array('user' => $user)));
             $auth = \Zend_Auth::getInstance();
             if ($auth->hasIdentity()) {
                 // show index
                 $this->_helper->flashMessenger('User registered successfully.');
                 $this->_helper->redirector('index', 'index', 'default');
             } else {
                 $adapter = $this->_helper->service('auth.adapter');
                 $adapter->setEmail($user->getEmail())->setPassword($values['password']);
                 $result = $auth->authenticate($adapter);
                 $this->_helper->redirector('index', 'dashboard', 'default', array('first' => 1));
             }
         } catch (\Exception $e) {
             switch ($e->getMessage()) {
                 case 'username_conflict':
                     $form->username->addError('Username is used. Please use another one.');
                     break;
                 default:
                     var_dump($e);
                     exit;
             }
         }
     }
     $this->view->form = $form;
 }