Skip to content

Instantly share code, notes, and snippets.

@ozten
Created June 22, 2012 10:17
Show Gist options
  • Select an option

  • Save ozten/2971878 to your computer and use it in GitHub Desktop.

Select an option

Save ozten/2971878 to your computer and use it in GitHub Desktop.
Newer watch based API for Drupal module
(function ($) {
// currentUser is null or '[email protected]'
var currentUser = "<?= loggedInUser ?>",
handleLogin,
handleLogout;
handleLogin = function (assertion) {
if (assertion) {
$.post(Drupal.settings.basePath +'index.php?q=browserid/verify', {
'assertion': assertion,
'token': Drupal.settings.browserid.token
}, function (data) {
if (data.reload) {
window.location.reload();
}
else if (data.destination) {
window.location.href = data.destination;
}
else {
alert(Drupal.t('An unknown error occurred while attempting to validate your BrowserID login. After clicking "OK," you will be redirected to a page where you can log in without BrowserID or try logging in with BrowserID again.'));
window.location.href = Drupal.settings.basePath + 'index.php?q=user/login';
}
});
}
};
handleLogout = function () {
window.location.href = Drupal.settings.basePath + 'index.php?q=user/logout';
};
navigator.id.watch({
loggedInEmail: currentUser,
onlogin: handleLogin,
onlogout: handleLogout,
onready: function () {
$(context).find('.browserid-button').show();
$(context).find('.browserid-button').click(function(e) {performLogin()});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment