function janrain_capture_init in Janrain Registration 7
Same name and namespace in other branches
- 7.4 janrain_capture.module \janrain_capture_init()
Implements hook_init().
File
- ./
janrain_capture.module, line 13 - This module implements authentication endpoints for Janrain Capture.
Code
function janrain_capture_init() {
// Don't do anything if the module settings have not been configured.
if (!janrain_capture_configured()) {
return;
}
$janrain_capture_main = variable_get('janrain_capture_main', array());
$janrain_capture_optional = variable_get('janrain_capture_optional', array());
$capture_sso_address = !empty($janrain_capture_optional['capture_sso_address']) ? $janrain_capture_optional['capture_sso_address'] : '';
$capture_client_id = !empty($janrain_capture_main['capture_client_id']) ? $janrain_capture_main['capture_client_id'] : '';
$uri_opts = array(
'absolute' => TRUE,
);
if ($_GET['q']) {
$uri_opts['query'] = array(
'destination' => $_GET['q'],
);
}
$settings = array(
'janrainCapture' => array(
'profile_sync_url' => url('janrain_capture/profile_sync', $uri_opts),
'token_expired_url' => url('janrain_capture/token_expired/' . drupal_get_token('janrain_capture_token_expired')),
'logout_url' => url('user/logout', array(
'absolute' => TRUE,
'real_logout' => TRUE,
)),
'enforce' => variable_get('janrain_capture_enforce', FALSE),
),
);
if (!empty($janrain_capture_optional['backplane_server']) && !empty($janrain_capture_optional['backplane_bus_name'])) {
$settings['janrainCapture']['backplane_server'] = $janrain_capture_optional['backplane_server'];
$settings['janrainCapture']['backplane_bus_name'] = $janrain_capture_optional['backplane_bus_name'];
}
if (!empty($capture_sso_address)) {
$settings['janrainCapture']['sso_address'] = $capture_sso_address;
}
drupal_add_js($settings, array(
'type' => 'setting',
'every_page' => TRUE,
));
// Add the jQuery BBQ plugin to handle destination redirects.
drupal_add_library('system', 'jquery.bbq', TRUE);
$scripts = array(
'file' => array(),
'inline' => array(),
'external' => array(),
);
$scripts['file'][] = drupal_get_path('module', 'janrain_capture') . '/janrain_capture.js';
$scripts['external'][] = 'https://d7v0k4dt27zlp.cloudfront.net/assets/capture_client.js';
if (!empty($capture_sso_address)) {
$scripts['external'][] = "https://{$capture_sso_address}/sso.js";
$scripts['inline'][] = '
var janrainCaptureClientId ="' . $capture_client_id . '";
var janrainCaptureRedirectUri ="' . url('janrain_capture/oauth', array(
'absolute' => TRUE,
)) . '";
var janrainCaptureLogoutUri ="' . url('user/logout', array(
'absolute' => TRUE,
'real_logout' => TRUE,
)) . '";
var janrainCaptureXdReceiver ="' . url(NULL, array(
'absolute' => TRUE,
)) . drupal_get_path('module', 'janrain_capture') . '/xdcomm.html";
if(undefined == "' . $janrain_capture_optional['backplane_bus_name'] . '") {
console.log("Not Federated");
JANRAIN.SSO.CAPTURE.check_login({
sso_server: "https://" + Drupal.settings.janrainCapture.sso_address,
client_id: janrainCaptureClientId,
redirect_uri: janrainCaptureRedirectUri,
logout_uri: janrainCaptureLogoutUri,
xd_receiver: janrainCaptureXdReceiver
});
}';
}
if (!empty($janrain_capture_optional['backplane_js_path'])) {
$scripts['external'][] = $janrain_capture_optional['backplane_js_path'];
}
if (isset($_SESSION['janrain_capture_password_recover']) && $_SESSION['janrain_capture_password_recover'] == TRUE) {
$url = url('janrain_capture/profile', array(
'absolute' => TRUE,
'query' => array(
'method' => '_change_password',
'callback' => 'Drupal.janrainCapture.closeRecoverPassword',
),
));
$scripts['inline'][] = 'jQuery(function($) {Drupal.janrainCapture.passwordRecover(' . $url . ')});';
$_SESSION['janrain_capture_password_recover'] = FALSE;
}
foreach ($scripts['file'] as $s) {
drupal_add_js($s, array(
'type' => 'file',
'every_page' => TRUE,
'weight' => 1,
));
}
foreach ($scripts['external'] as $s) {
drupal_add_js($s, array(
'type' => 'external',
'every_page' => TRUE,
'weight' => 2,
));
}
foreach ($scripts['inline'] as $s) {
drupal_add_js($s, array(
'type' => 'inline',
'every_page' => TRUE,
'weight' => 3,
));
}
}