/**
  * this is just a stub for post-login redirects. 
  * make sure we hydrate the user's session with fresh new user data before passing them on.
  */
 public function bootstrap()
 {
     if (Auth::guest()) {
         return Redirect::to($this->base_uri . 'login');
     }
     Session_Filter::hydrate();
     if (Session::has('desired_uri')) {
         $desired_uri = Session::get('desired_uri');
         Session::forget('desired_uri');
         return Redirect::to($desired_uri);
     }
     $panel_uri = Session::get('user_data.starting_panel_uri');
     return Redirect::to($panel_uri);
 }
 public function do_create($panel_name)
 {
     $panel = new Panel();
     $user_scope = $panel->user_scope($panel_name, 'C', $this->subpanel_parent);
     // can we create? which fields?
     if (!$user_scope) {
         return Redirect::back()->with('error', 'You do not have access to that area.');
     }
     $this->init($panel_name, 'C');
     $override_response = $this->override_responded_to($user_scope, 'C');
     if ($override_response) {
         return $override_response;
     }
     $validator = $panel->validates_against($panel_name, $user_scope);
     $attempt_uri = isset($this->is_creating_user) ? '/' . $this->base_uri . 'register/' : '/' . $this->base_uri . 'panel/' . $panel_name . '/create';
     $attempt_uri = $attempt_uri . $this->append_attempt_uri;
     if ($validator->fails()) {
         // flash error and redirect to form
         if (Request::ajax()) {
             $errors = array('ajax_errors' => $validator->getMessageBag()->toArray());
             $error_flash = View::make('station::layouts.header', $errors)->render();
             return Response::json(['status' => 0, 'flash' => $error_flash]);
         } else {
             return Redirect::to($attempt_uri)->withErrors($validator)->withInput();
         }
     } else {
         // save and redirect
         // Is there a pre_trigger?
         if (isset($this->panel_config['panel_options']['trigger']['pre']['C'])) {
             $temp = explode('@', $this->panel_config['panel_options']['trigger']['pre']['C']);
             $override_controller = $temp[0];
             $override_method = $temp[1];
             App::make($override_controller)->{$override_method}(Input::all());
         }
         $record_id = $panel->create_record_for($panel_name, $user_scope, isset($this->is_creating_user), $this->write_data_override);
         if (is_numeric($record_id)) {
             // record was saved
             // Is there a post_trigger?
             if (isset($this->panel_config['panel_options']['trigger']['post']['C'])) {
                 $temp = explode('@', $this->panel_config['panel_options']['trigger']['post']['C']);
                 $override_controller = $temp[0];
                 $override_method = $temp[1];
                 App::make($override_controller)->{$override_method}($record_id);
             }
             if (Request::ajax()) {
                 return Response::json(['status' => 1, 'record_id' => $record_id]);
             } else {
                 if (isset($this->is_creating_user)) {
                     // this is a new account. find out where they should go first, log them in and redirect
                     Auth::loginUsingId($record_id);
                     Station_Session::hydrate();
                     $uri = Session::get('user_data.starting_panel_uri');
                     $message = 'Your account has been added and you are logged in!';
                 } else {
                     // just creating a new record in general
                     $user_wants_to_create_another = Input::get('after_save') == 'create';
                     $append = $this->subpanel_parent_uri != '' ? $this->subpanel_parent_uri : '/' . $panel_name;
                     $uri = '/' . $this->base_uri . 'panel' . $append;
                     $uri = $user_wants_to_create_another ? $attempt_uri : $uri;
                     $message = 'Your new ' . strtolower($this->single_item_name) . ' has been added. ';
                     $message .= $user_wants_to_create_another ? 'Create a another below.' : '';
                 }
                 return Redirect::to($uri)->with('success', $message);
             }
         }
         return Redirect::to($attempt_uri)->with('error', 'Something went wrong with saving :(');
         // TODO: log this.
     }
 }