public function indexAction()
 {
     if (!$this->request->isPost()) {
         return;
     }
     if ($this->request->isAjax() || $this->request->get('ajax')) {
         $form = new Forms\RegisterForm();
         if ($form->isValid($this->request->getPost()) === false) {
             return $this->showInvalidMessagesAsJson($form);
         }
         $user = new Models\Register();
         $user->assign(array('username' => $this->request->getPost('username'), 'email' => $this->request->getPost('email'), 'password' => $this->request->getPost('password'), 'usernameCustomized' => 1, 'providerType' => $user->getProviderType('web', 'manual', 'email'), 'source' => Models\LoginRecord::getSourceOfUser()));
         try {
             $registerUser = $user->register();
             return $this->showResponseAsJson($registerUser);
         } catch (\Exception $e) {
             return $this->showExceptionAsJson($e, $user->getMessages());
         }
     } else {
         $form = new Forms\RegisterForm();
         $registerSuccessRedirectUri = $this->dispatcher->getParam('registerSuccessRedirectUri');
         $registerSuccessRedirectUri = $registerSuccessRedirectUri ? $registerSuccessRedirectUri : $this->getDI()->getConfig()->user->registerSuccessRedirectUri;
         $registerFailedRedirectUri = $this->dispatcher->getParam('registerFailedRedirectUri');
         $registerFailedRedirectUri = $registerFailedRedirectUri ? $registerFailedRedirectUri : $this->getDI()->getConfig()->user->registerFailedRedirectUri;
         $registerFailedRedirectUri = $registerFailedRedirectUri ? $registerFailedRedirectUri : $this->request->getURI();
         if ($form->isValid($this->request->getPost()) === false) {
             $this->showInvalidMessages($form);
             return $this->redirectHandler($registerFailedRedirectUri, 'error');
         }
         $user = new Models\Register();
         $user->assign(array('username' => $this->request->getPost('username'), 'email' => $this->request->getPost('email'), 'password' => $this->request->getPost('password'), 'usernameCustomized' => 1, 'providerType' => $user->getProviderType('web', 'manual', 'email'), 'source' => Models\LoginRecord::getSourceOfUser()));
         try {
             $user->register();
         } catch (\Exception $e) {
             $this->showException($e, $user->getMessages());
             return $this->redirectHandler($registerFailedRedirectUri, 'error');
         }
         $this->flashSession->success('SUCCESS_USER_REGISTERED_ACTIVE_MAIL_SENT');
         return $this->redirectHandler($registerSuccessRedirectUri);
     }
 }
 public function indexAction()
 {
     if (!$this->request->isPost()) {
         return;
     }
     if ($this->request->isAjax()) {
         $form = new Forms\RegisterForm();
         if ($form->isValid($this->request->getPost()) === false) {
             return $this->showInvalidMessagesAsJson($form);
         }
         $user = new Models\Register();
         $user->assign(array('username' => $this->request->getPost('username'), 'email' => $this->request->getPost('email'), 'password' => $this->request->getPost('password')));
         $transaction = $this->getDI()->getTransactions()->get();
         try {
             $transaction->begin();
             $registerUser = $user->register();
             $transaction->commit();
             return $this->showResponseAsJson($registerUser);
         } catch (\Exception $e) {
             $transaction->rollback();
             return $this->showExceptionAsJson($e, $user->getMessages());
         }
     } else {
         $form = new Forms\RegisterForm();
         if ($form->isValid($this->request->getPost()) === false) {
             $this->showInvalidMessages($form);
             return $this->redirectHandler($this->getDI()->getConfig()->user->registerFailedRedirectUri, 'error');
         }
         $user = new Models\Register();
         $user->assign(array('username' => $this->request->getPost('username'), 'email' => $this->request->getPost('email'), 'password' => $this->request->getPost('password')));
         try {
             $user->register();
         } catch (\Exception $e) {
             $this->showException($e, $user->getMessages());
             return $this->redirectHandler($this->getDI()->getConfig()->user->registerFailedRedirectUri, 'error');
         }
         $this->flashSession->success('SUCCESS_USER_REGISTERED_ACTIVE_MAIL_SENT');
         return $this->redirectHandler($this->getDI()->getConfig()->user->registerSuccessRedirectUri);
     }
 }