public function mobileAction()
 {
     if (!$this->request->isPost()) {
         return;
     }
     $data = $this->request->getPost();
     //配资姓名不需要username 和 email ,但是去掉对原有的登录系统又风险,所以先做个假的
     //        $data['username'] = '******'.$data['mobile'];
     //        $randomNumber = chr(mt_rand(97, 122));
     //        $data['username'] = $data['mobile'] . '_' . $randomNumber;
     $data['username'] = '******' . uniqid() . substr($data['mobile'], 7);
     $data['email'] = $data['mobile'] . '@fake.wallstreetcn.com';
     //        $data['screenName'] =
     //            substr($data['mobile'], 0, 3) . '******' . substr($data['mobile'], -2) . '_' . $randomNumber;
     if ($this->request->isAjax() || $this->request->get('ajax')) {
         $form = new Forms\MobileRegisterForm();
         if ($form->isValid($data) === false) {
             return $this->showInvalidMessagesAsJson($form);
         }
         $user = new Models\Register();
         $user->assign(array('email' => $data['email'], 'username' => $data['username'], 'mobile' => $this->request->getPost('mobile'), 'password' => $this->request->getPost('password'), 'screenName' => $data['screenName'], 'usernameCustomized' => 0, 'providerType' => $user->getProviderType('web', 'manual', 'mobile'), 'source' => Models\LoginRecord::getSourceOfUser()));
         $captcha = $this->request->getPost('captcha');
         try {
             $registerUser = $user->registerByMobile($captcha);
             return $this->showResponseAsJson($registerUser);
         } catch (\Exception $e) {
             return $this->showExceptionAsJson($e, $user->getMessages());
         }
     } else {
         $form = new Forms\MobileRegisterForm();
         if ($form->isValid($data) === false) {
             $this->showInvalidMessages($form);
             return $this->redirectHandler($this->getDI()->getConfig()->user->registerFailedRedirectUri, 'error');
         }
         $user = new Models\Register();
         $user->assign(array('username' => $data['username'], 'mobile' => $this->request->getPost('mobile'), 'password' => $this->request->getPost('password'), 'providerType' => $user->getProviderType('web', 'manual', 'mobile'), 'source' => Models\LoginRecord::getSourceOfUser()));
         $captcha = $this->request->getPost('captcha');
         try {
             $user->registerByMobile($captcha);
         } 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);
     }
 }
 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);
     }
 }