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); }
public function post_users() { $train_id = Input::post('train_id'); if ($train_id) { $state = Model_Userstate::find('all', ['where' => [['train_id', $train_id]]]); $this->response($state); } else { $this->response([]); } }
public function action_getoffdriver() { $data['userstates'] = Model_Userstate::find('all'); $this->template->title = "GetoffDriver for development!"; $this->template->content = View::forge('userstate/getoff', $data); }