public function login($credentials)
{
$user = $credentials['user'];
$password = $credentials['password'];
$this->_client = new \Oara\Curl\Access($credentials);
$url = "https://www.privateinternetaccess.com/affiliates/sign_in";
$valuesLogin = array(new \Oara\Curl\Parameter('affiliate[email]', $user), new \Oara\Curl\Parameter('affiliate[password]', $password));
$urls = array();
$urls[] = new \Oara\Curl\Request($url, $valuesLogin);
$exportReport = $this->_client->post($urls);
$doc = new \DOMDocument();
@$doc->loadHTML($exportReport[0]);
$xpath = new \DOMXPath($doc);
$results = $xpath->query('//input[@type="hidden"]');
$hiddenValue = null;
foreach ($results as $result) {
$name = $result->attributes->getNamedItem("name")->nodeValue;
if ($name == "authenticity_token") {
$hiddenValue = $result->attributes->getNamedItem("value")->nodeValue;
}
}
if ($hiddenValue == null) {
throw new \Exception("hidden value not found");
}
$valuesLogin = array(new \Oara\Curl\Parameter('authenticity_token', $hiddenValue), new \Oara\Curl\Parameter('affiliate[email]', $user), new \Oara\Curl\Parameter('affiliate[password]', $password), new \Oara\Curl\Parameter('utf8', '✓'), new \Oara\Curl\Parameter('commit', 'Login'), new \Oara\Curl\Parameter('affiliate[remember_me]', '0'));
$urls = array();
$urls[] = new \Oara\Curl\Request($url, $valuesLogin);
$this->_client->post($urls);
}