Exemplo n.º 1
0
 /**
  * ユーザ登録
  *
  * @access  public
  * @return  View
  */
 public function action_signup()
 {
     //認証チェック
     if (\Auth::check()) {
         Response::redirect('mypage');
     }
     $view = View::forge('auth/signup');
     //フォーム生成
     $form = Formparts::signup();
     //入力有り
     if (\Input::post()) {
         if (!\Security::check_token()) {
             $view->set_global('massage', array('css' => 'warning', 'content' => '再読み込みは無効な操作です。'));
         } else {
             //
             if (\Input::post('password') != \Input::post('re-password')) {
                 $form->repopulate();
                 $view->set_global('massage', array('css' => 'warning', 'content' => 'パスワードが一致していません。'));
             } else {
                 $val = $form->validation();
                 if ($val->run()) {
                     try {
                         $result = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), 1, array('firstname' => \Input::post('firstname'), 'lastname' => \Input::post('lastname')));
                         if ($result) {
                             if (\Auth::instance()->login(\Input::post('username'), \Input::post('password'))) {
                                 // ログインしマイページに移動
                                 return \Response::redirect('mypage');
                             } else {
                                 $view->set_global('massage', array('css' => 'danger', 'content' => '予期せぬエラーです。'));
                             }
                         }
                     } catch (\SimpleUserUpdateException $e) {
                         switch ($e->getCode()) {
                             case 2:
                                 // メールアドレスが重複
                                 $view->set_global('massage', array('css' => 'warning', 'content' => 'メールアドレスが重複しています。'));
                                 break;
                             case 3:
                                 // ユーザー名が重複
                                 $view->set_global('massage', array('css' => 'warning', 'content' => 'ユーザ名が重複しています。'));
                                 break;
                             default:
                                 // これは起こり得ないが、ずっとそうとは限らない...
                                 $view->set_global('massage', array('css' => 'danger', 'content' => '予期せぬエラーです。'));
                         }
                     }
                 } else {
                     $form->repopulate();
                     $view->set_global('errors', $val->error());
                 }
             }
         }
     }
     //		$form->build();
     $view->set_safe('form', $form);
     return $view;
 }