Esempio n. 1
0
 public function twitter_login($response = null)
 {
     $uid = (string) $response['auth']['uid'];
     $query = Model_Twitteruser::query()->where('uid', $uid);
     if ($query->count() == 0) {
         // TwitterUser未登録の場合はサインアップ
         //return $this->twitter_signup($response);
         $data['name'] = $response['auth']['info']['nickname'];
         //登録時に必要な情報をセッションで保持しておく
         Session::set('uid', (string) $response['auth']['uid']);
         Session::set('token', $response['auth']['credentials']['token']);
         Session::set('secret', $response['auth']['credentials']['secret']);
         Session::set('nickname', $response['auth']['info']['nickname']);
         //初期駅取得
         /*
         $sql = "
             select
                 concat( s.title, ' (', r.title, '線) ') as name
               , substring(s.id, 6) as value
             from StationOrders so, Railways r, Stations s
             where so.Railway_id = r.id
               and so.station = s.id
             order by so.Railway_id, so.index";
         
         $query = DB::query($sql);
         $result = $query->execute()->as_array();
         $stations = array();
         foreach($result as $item)
         {
             $stations += array($item['value']=>$item['name']);
         }
         $data['stations'] = $stations;
         
         //性別と初期駅を登録する画面に遷移
         $this->template->title = "初期設定";
         $this->template->content = View::forge('auth/init', $data);
         return;
         */
     } else {
         $twitter_user = $query->get_one();
         $user_id = $twitter_user->user_id;
         Model_User::login_twitter($user_id);
     }
     Response::redirect('portal/callback');
     // TwitterUser登録済みの場合はログイン
     //$twitter_user = $query->get_one();
     //return $this->login_succeeded($twitter_user->user_id);
 }
Esempio n. 2
0
 public function action_entry()
 {
     // 登録時
     if (Input::method() == 'POST') {
         // バリデーション
         $val = Model_Twitteruser::validate('create');
         $input = array('uid' => Session::get('uid'), 'token' => Session::get('token'), 'secret' => Session::get('secret'));
         if ($val->run($input)) {
             // バリデーション成功時
             $user = Model_User::forge(array('name' => Session::get('nickname'), 'password' => substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyz'), 0, 10), 'sex' => Input::post('sex'), 'birth_station_id' => Input::post('birth_station_id')));
             $twitter_user = Model_TwitterUser::forge($input);
             if ($user and $twitter_user) {
                 // ユーザー生成成功
                 try {
                     \DB::start_transaction();
                     if ($user->save() === false) {
                         // User保存失敗
                         throw new \Exception('user save failed.');
                     }
                     $twitter_user->user_id = $user->id;
                     if ($twitter_user->save() === false) {
                         // TwitterUser保存失敗
                         throw new \Exception('twitter_user save failed.');
                     }
                     //その他Userに付随する情報を作成
                     //user_state
                     $state = Model_Userstate::forge(array('id' => $user->id, 'ride_state' => '0', 'now_station_id' => $user->birth_station_id));
                     if ($state->save() === false) {
                         // user_state保存失敗
                         throw new \Exception('user_state save failed.');
                     }
                     //user_fortune
                     //ポイントは動的にできるように。。。
                     $fortune = Model_Userfortune::forge(array('id' => $user->id, 'points' => 10000, 'domination1' => ' ', 'domination2' => ' ', 'domination3' => ' '));
                     if ($fortune->save() == false) {
                         // user_state保存失敗
                         throw new \Exception('user_fortune save failed.');
                     }
                     // 保存成功
                     \DB::commit_transaction();
                     //サインアップ成功なのでいらないSessionは消す
                     Session::delete('uid');
                     Session::delete('token');
                     Session::delete('secret');
                     Session::delete('nickname');
                     Model_User::login_twitter($user->id);
                     Response::redirect('portal');
                 } catch (\Exception $e) {
                     \DB::rollback_transaction();
                     Response::redirect('portal');
                 }
             } else {
                 // ユーザー生成失敗
                 Response::redirect('portal');
             }
         } else {
             // バリデーション失敗時
             Response::redirect('portal');
         }
         // 登録できたら ポータルに戻る.
     }
     // Viewに受け渡す用
     $exp = ['name' => Session::get('nickname'), 'stations' => Model_Traininfo::get_birth_train_summary()];
     $this->template->title = '新規アカウント登録';
     $this->template->content = View_Twig::forge('portal/entry', $exp);
 }