Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
 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);
     }
 }
Beispiel #3
0
 public function register()
 {
     $accessToken = OAuthManager::getAccessToken();
     if (!$accessToken) {
         throw new Exception\ResourceConflictException('ERR_OAUTH_NO_ACCESS_TOKEN');
     }
     $register = new UserRegister();
     $register->username = $this->username;
     $register->email = $this->email;
     $register->status = 'active';
     $register->accountType = 'basic';
     $register->emailStatus = 'inactive';
     $register->providerType = $accessToken['adapterKey'] . '_' . $accessToken['version'];
     $user = $register->register(true);
     $accessTokenEntity = new AccessTokens();
     $accessTokenEntity->assign($accessToken);
     $accessTokenEntity->tokenStatus = 'active';
     $accessTokenEntity->userId = $user->id;
     if (!$accessTokenEntity->save()) {
         throw new Exception\RuntimeException('ERR_OAUTH_TOKEN_CREATE_FAILED');
     }
     return $user;
 }