Beispiel #1
0
 protected function _edit_agent()
 {
     $t = $this->_template;
     $t->add('_jsapps', 'agent_form');
     $storage = \Core\Storage::container()->get_storage('Agent');
     $mapper = \Trouble\Agent::mapper()->attach_storage($storage);
     $t->errors = array();
     if ($this->_args['alias']) {
         $t->title = "Edit Agent";
         $agent = \Trouble\Agent::container()->get_by_alias($this->_args['alias']);
         $this->_auth->check_admin('agent', $agent->id);
     } else {
         try {
             $t->title = "Edit Yourself";
             $agent = \Trouble\Agent::container()->get_by_id($this->_auth->user_id());
         } catch (\Core\AuthNotLoggedInError $e) {
             $t->title = "Agent Application";
             $t->new = True;
             $agent = \Trouble\Agent::create();
         }
     }
     $t->agent = $agent;
     return $t->render('forms/agent.php');
 }
Beispiel #2
0
 protected function _intel()
 {
     $t = $this->_template;
     $a = \Trouble\Agent::container()->get_by_alias($this->_args['agent_alias']);
     $t->agent = $a;
     $t->player = $this->_player;
     $targ = $this->_game->all_players->filter($a->id, 'agent')->{0};
     if ($targ->id == $t->player->target && $t->player->status == 1) {
         $t->is_target = True;
         $t->_dialog_kill = $t->render('forms/kill.php');
     }
     $t->owned_intels = \Trouble\OwnedIntel::container()->get_owned_intel($a, $this->_player);
     return $t->render('intel.php');
 }
Beispiel #3
0
 /**
  * TODO: restrict agent to logged in user or admin
  */
 public function save_agent()
 {
     import('core.validation');
     import('trouble.agent');
     $validator = \Core\Validator::validator('\\Trouble\\Agent');
     $editing = $_POST['id'] > 0 ? True : False;
     try {
         if ($editing) {
             if ($_POST['id'] != $this->_auth->user_id()) {
                 $this->_auth->check_admin('agent', $_POST['id']);
             }
             $agent = \Trouble\Agent::container()->get_by_id($_POST['id']);
             $validator->set_id($agent->id);
             $_POST['alias'] = $agent->alias;
             $agent->overwrite($_POST, True);
         } else {
             if (empty($_POST['password'])) {
                 throw new \Core\ValidationError(array('Password must be set on creation.'));
             }
             $agent = \Trouble\Agent::create($_POST, True);
         }
         $validator->validate($_POST);
         try {
             \Core\Auth::hash($agent, 'password');
         } catch (\Core\AuthEmptyPasswordError $e) {
             $agent->remove('password');
         }
         \Core\Storage::container()->get_storage('Agent')->save($agent);
         if ($editing) {
             $this->_auth->user_data($agent);
             echo $this->_return_message("Success", "Saved.");
         } else {
             echo $this->_return_message("Success", "Created agent. You may now log in.");
         }
     } catch (\Core\ValidationError $e) {
         echo $this->_return_message("Fail", "Validation error(s):", $e->get_errors());
     } catch (\Core\AuthNotLoggedInError $e) {
         $this->_not_logged_in();
     } catch (\Core\AuthDeniedError $e) {
         $this->_access_denied();
     } catch (\Exception $e) {
         $this->_unhandled_exception($e);
     }
 }
Beispiel #4
0
 protected function _init_agent($alias)
 {
     $this->_agent = \Trouble\Agent::container()->get_by_alias($alias);
 }