/** * Takes an RPCUser username and password and, if valid, returns a new RPC Session * to be used in further communications. * * @arg string Username to log in as * @arg string Password to for this username * * @param object $method The name of the RPC method * @param object $args An array of arguements, listed above * @return string The session code * @throws RPCException */ public function login($method, $args) { if (count($args) < 2) { throw new RPCException('Invalid arguements', 500); } $struct = RPCUser::login($args[0], $args[1]); if ($struct['code'] == 200) { try { $session = $struct['user']->createSession(Site::RemoteIP()); return $session->code; } catch (Error500 $e) { throw new RPCException($e->getMessage(), 500); } } else { throw new RPCException($struct['error'], $struct['code']); } }
protected static function load_rpcuser($id = null) { if (!$id) { $id = $_GET['id']; } $user = RPCUser::find_by_id($id); if ($user) { return $user; } else { throw new Error404('Unable to find RPC User'); } }
public static function load_from_row($row, $recurse_limit = 1, $current_level = 0) { // When PHP 5.3.0 is in, we can shift this over too and just redefine it // if needed (eg. loading child objects) $class = __CLASS__; $object = new $class(); $fields = self::fields_array(); $fields[] = array("created_at", "datetime"); $fields[] = array("updated_at", "datetime"); $fields[] = array("deleted", "bool"); foreach ($fields as $field) { $property = $field[0]; if (isset($field[2])) { $property = $field[2]; } if (isset($row[self::table . ".{$field[0]}"])) { if ($field[1] == "datetime") { $object->{$property} = strtotime($row[self::table . ".{$field[0]}"]); } else { $object->{$property} = $row[self::table . ".{$field[0]}"]; } } else { $object->{$property} = null; } } $object->is_new = false; // Load child objects here if ($current_level < $recurse_limit) { $current_level++; $object->rpcuser = RPCUser::load_from_row($row, $recurse_limit, $current_level); } return $object; }