AmyRemoteProject::authenticate PHP Method

authenticate() public static method

public static authenticate ( $project_url, $username, $password, $requestParams = [] )
    public static function authenticate($project_url, $username, $password, $requestParams = array())
    {
        $url = fix_parse_url($project_url);
        $response = SimpleHTTP::send('POST', $url['host'], $url['port'], $url['path'], array_merge($requestParams, array('a' => 'authenticate', 'username' => $username, 'password' => $password)));
        if ('200' != $response['status_code']) {
            throw new Exception("Invalid status code `{$response['status_code']}' returned from server `{$url['host']}'.");
        }
        $response = trim($response['body']);
        if ('' === $response) {
            throw new Exception("Unable to authenticate project, no content returned from `{$url['host']}{$url['path']}'.");
        }
        if ('#S#' == substr($response, 0, 3)) {
            // returning ticket
            return substr($response, 3);
        }
        throw new Exception(substr($response, 3));
    }

Usage Example

 public function on_project_authenticate($pars = array())
 {
     try {
         self::setResult(AmyRemoteProject::authenticate($pars['url'], $pars['username'], $pars['password'], $_REQUEST));
     } catch (Exception $e) {
         $err_msg = $e->getMessage();
         self::raiseError("Project could not been authenticated due an error: `{$err_msg}'.");
     }
 }