diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Gdata/ClientLogin.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Gdata/ClientLogin.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,182 @@ +setUri($loginUri); + $useragent = $source . ' Zend_Framework_Gdata/' . Zend_Version::VERSION; + $client->setConfig(array( + 'maxredirects' => 0, + 'strictredirects' => true, + 'useragent' => $useragent + ) + ); + $client->setParameterPost('accountType', $accountType); + $client->setParameterPost('Email', (string) $email); + $client->setParameterPost('Passwd', (string) $password); + $client->setParameterPost('service', (string) $service); + $client->setParameterPost('source', (string) $source); + if ($loginToken || $loginCaptcha) { + if($loginToken && $loginCaptcha) { + $client->setParameterPost('logintoken', (string) $loginToken); + $client->setParameterPost('logincaptcha', + (string) $loginCaptcha); + } + else { + require_once 'Zend/Gdata/App/AuthException.php'; + throw new Zend_Gdata_App_AuthException( + 'Please provide both a token ID and a user\'s response ' . + 'to the CAPTCHA challenge.'); + } + } + + // Send the authentication request + // For some reason Google's server causes an SSL error. We use the + // output buffer to supress an error from being shown. Ugly - but works! + ob_start(); + try { + $response = $client->request('POST'); + } catch (Zend_Http_Client_Exception $e) { + require_once 'Zend/Gdata/App/HttpException.php'; + throw new Zend_Gdata_App_HttpException($e->getMessage(), $e); + } + ob_end_clean(); + + // Parse Google's response + $goog_resp = array(); + foreach (explode("\n", $response->getBody()) as $l) { + $l = chop($l); + if ($l) { + list($key, $val) = explode('=', chop($l), 2); + $goog_resp[$key] = $val; + } + } + + if ($response->getStatus() == 200) { + $client->setClientLoginToken($goog_resp['Auth']); + $useragent = $source . ' Zend_Framework_Gdata/' . Zend_Version::VERSION; + $client->setConfig(array( + 'strictredirects' => true, + 'useragent' => $useragent + ) + ); + return $client; + + } elseif ($response->getStatus() == 403) { + // Check if the server asked for a CAPTCHA + if (array_key_exists('Error', $goog_resp) && + $goog_resp['Error'] == 'CaptchaRequired') { + require_once 'Zend/Gdata/App/CaptchaRequiredException.php'; + throw new Zend_Gdata_App_CaptchaRequiredException( + $goog_resp['CaptchaToken'], $goog_resp['CaptchaUrl']); + } + else { + require_once 'Zend/Gdata/App/AuthException.php'; + throw new Zend_Gdata_App_AuthException('Authentication with Google failed. Reason: ' . + (isset($goog_resp['Error']) ? $goog_resp['Error'] : 'Unspecified.')); + } + } + } + +} +