本文整理汇总了PHP中Gdn_Controller::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Controller::setHeader方法的具体用法?PHP Gdn_Controller::setHeader怎么用?PHP Gdn_Controller::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Controller
的用法示例。
在下文中一共展示了Gdn_Controller::setHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: base_connectData_handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function base_connectData_handler($Sender, $Args)
{
if (val(0, $Args) != 'facebook') {
return;
}
if (isset($_GET['error'])) {
// TODO global nope x2
throw new Gdn_UserException(val('error_description', $_GET, t('There was an error connecting to Facebook')));
}
$AppID = c('Plugins.Facebook.ApplicationID');
$Secret = c('Plugins.Facebook.Secret');
$Code = val('code', $_GET);
// TODO nope
$Query = '';
if ($Sender->Request->get('display')) {
$Query = 'display=' . urlencode($Sender->Request->get('display'));
}
$RedirectUri = concatSep('&', $this->redirectUri(), $Query);
$AccessToken = $Sender->Form->getFormValue('AccessToken');
// Get the access token.
if (!$AccessToken && $Code) {
// Exchange the token for an access token.
$Code = urlencode($Code);
$AccessToken = $this->getAccessToken($Code, $RedirectUri);
$NewToken = true;
}
// Get the profile.
try {
$Profile = $this->getProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
redirect($this->authorizeUri());
} else {
$Sender->setHeader('Content-type', 'application/json');
$Sender->deliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->authorizeUri();
}
} else {
$Sender->Form->addError('There was an error with the Facebook connection.');
}
}
$Form = $Sender->Form;
//new Gdn_Form();
$ID = val('id', $Profile);
$Form->setFormValue('UniqueID', $ID);
$Form->setFormValue('Provider', self::ProviderKey);
$Form->setFormValue('ProviderName', 'Facebook');
$Form->setFormValue('FullName', val('name', $Profile));
$Form->setFormValue('Email', val('email', $Profile));
$Form->setFormValue('Photo', "//graph.facebook.com/{$ID}/picture?width=200&height=200");
$Form->addHidden('AccessToken', $AccessToken);
if (c('Plugins.Facebook.UseFacebookNames')) {
$Form->setFormValue('Name', val('name', $Profile));
saveToConfig(array('Garden.User.ValidationRegex' => UserModel::USERNAME_REGEX_MIN, 'Garden.User.ValidationLength' => '{3,50}', 'Garden.Registration.NameUnique' => false), '', false);
}
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array();
$Attributes[self::ProviderKey] = array('AccessToken' => $AccessToken, 'Profile' => $Profile);
$Form->setFormValue('Attributes', $Attributes);
$Sender->setData('Verified', true);
}
示例2: base_connectData_handler
/**
*
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function base_connectData_handler($Sender, $Args)
{
if (val(0, $Args) != 'twitter') {
return;
}
$Form = $Sender->Form;
//new Gdn_Form();
$RequestToken = val('oauth_token', $_GET);
$AccessToken = $Form->getFormValue('AccessToken');
if ($AccessToken) {
$AccessToken = $this->getOAuthToken($AccessToken);
$this->accessToken($AccessToken);
}
// Get the access token.
if ($RequestToken && !$AccessToken) {
// Get the request secret.
$RequestToken = $this->getOAuthToken($RequestToken);
$Consumer = new OAuthConsumer(c('Plugins.Twitter.ConsumerKey'), c('Plugins.Twitter.Secret'));
$Url = 'https://api.twitter.com/oauth/access_token';
$Params = array('oauth_verifier' => val('oauth_verifier', $_GET));
$Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
$SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
$Post = $Request->to_postdata();
$Curl = $this->_Curl($Request);
$Response = curl_exec($Curl);
if ($Response === false) {
$Response = curl_error($Curl);
}
$HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
curl_close($Curl);
if ($HttpCode == '200') {
$Data = OAuthUtil::parse_parameters($Response);
$AccessToken = new OAuthToken(val('oauth_token', $Data), val('oauth_token_secret', $Data));
// Save the access token to the database.
$this->setOAuthToken($AccessToken->key, $AccessToken->secret, 'access');
$this->accessToken($AccessToken->key, $AccessToken->secret);
// Delete the request token.
$this->deleteOAuthToken($RequestToken);
} else {
// There was some sort of error.
throw new Exception('There was an error authenticating with twitter.', 400);
}
$NewToken = true;
}
// Get the profile.
try {
$Profile = $this->getProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
redirect($this->_AuthorizeHref());
} else {
$Sender->setHeader('Content-type', 'application/json');
$Sender->deliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->_authorizeHref();
}
} else {
throw $Ex;
}
}
$ID = val('id', $Profile);
$Form->setFormValue('UniqueID', $ID);
$Form->setFormValue('Provider', self::ProviderKey);
$Form->setFormValue('ProviderName', 'Twitter');
$Form->setValue('ConnectName', val('screen_name', $Profile));
$Form->setFormValue('Name', val('screen_name', $Profile));
$Form->setFormValue('FullName', val('name', $Profile));
$Form->setFormValue('Photo', val('profile_image_url_https', $Profile));
$Form->addHidden('AccessToken', $AccessToken->key);
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array(self::ProviderKey => array('AccessToken' => array($AccessToken->key, $AccessToken->secret), 'Profile' => $Profile));
$Form->setFormValue('Attributes', $Attributes);
$Sender->setData('Verified', true);
}