Ejemplo n.º 1
0
 public function run()
 {
     $request = Yii::$app->getRequest();
     $form = new RegisterForm();
     if ($request->isPost) {
         $form->attributes = $request->post('RegisterForm');
         $form->recaptcha_token = $request->post('recaptcha');
         $form->recaptcha_response = $request->post('g-recaptcha-response');
         if ($form->validate()) {
             $user = $form->toUserModel();
             if ($user->save()) {
                 // ログインの動きを統一するためにログインフォームで認証かける
                 $login = new LoginForm();
                 $login->screen_name = $form->screen_name;
                 $login->password = $form->password;
                 if ($login->login()) {
                     return $this->controller->redirect(Yii::$app->user->getReturnUrl());
                 }
             }
         }
     }
     return $this->controller->render('login.tpl', ['login' => new RegisterForm(), 'register' => $form]);
 }