function gauth_login_user_login_submit in Google Auth 7.2
Same name and namespace in other branches
- 7 gauth_login/gauth_login.module \gauth_login_user_login_submit()
Login using google, submit handler
1 string reference to 'gauth_login_user_login_submit'
- gauth_login_form_alter in gauth_login/
gauth_login.module - Implements hook_form_alter().
File
- gauth_login/
gauth_login.module, line 172 - Google Auth Api for drupal.
Code
function gauth_login_user_login_submit() {
if (variable_get('gauth_login_client_id', FALSE)) {
$info = libraries_load('google-api-php-client');
if (!$info['loaded']) {
drupal_set_message(t("Can't authenticate with google as library is missing check Status report or Readme for requirements"), 'error');
return FALSE;
}
$client = new Google_Client();
$client
->setApplicationName("Google OAuth2");
$client
->setClientId(variable_get('gauth_login_client_id'));
$client
->setClientSecret(variable_get('gauth_login_client_secret'));
$client
->setRedirectUri(gauth_callback_url());
$client
->setDeveloperKey(variable_get('gauth_login_developer_key'));
$scopes = gauth_google_services_scopes('oauth2');
$client
->addScope($scopes);
if (!isset($_SESSION['gauth_login_state'])) {
$state = array(
'src' => 'gauth_login',
'hash' => md5(rand()),
);
if (isset($_GET['destination'])) {
$state['destination'] = $_GET['destination'];
unset($_GET['destination']);
}
}
else {
$state = $_SESSION['gauth_login_state'];
}
$_SESSION['gauth_login_state'] = $state;
$state = drupal_json_encode($state);
$client
->setState($state);
$url = $client
->createAuthUrl();
if ($restrict_domain = variable_get('gauth_login_domain_restriction', FALSE)) {
$url .= '&hd=' . $restrict_domain;
}
drupal_goto($url);
}
else {
drupal_set_message(t('Gauth Login is not configured. Please contact site administrator'), 'error');
}
}