Skip to content

Instantly share code, notes, and snippets.

@scan
Forked from anonymous/persona.coffee
Created July 6, 2013 14:48
Show Gist options
  • Save scan/5940127 to your computer and use it in GitHub Desktop.
Save scan/5940127 to your computer and use it in GitHub Desktop.
$ ->
($ '#login-btn').click ->
navigator.id.request
siteName: 'neighr'
#siteLogo: '/logo.png'
false
($ '#logout-btn').click ->
navigator.id.logout()
false
user = window.currentUser
user = null unless user
navigator.id.watch
loggedInUser: window.currentUser
onlogin: (assertion) ->
$.ajax
type: 'POST'
url: '/verify'
cache: no
dataType: 'json'
data:
assertion: assertion
_csrf: window._csrf
success: (res, status, xhr) ->
if res.redirect
window.location = res.redirect
else
window.location.reload()
error: (xhr, status, err) ->
navigator.id.logout()
alert "Login failure: #{err}"
onlogout: ->
$.ajax
type: 'POST'
url: '/logout'
data:
_csrf: window._csrf
success: (res, status, xhr) -> window.location = '/'
error: (xhr, status, err) -> alert "Logout failure: #{err}"
// Generated by CoffeeScript 1.6.3
(function() {
$(function() {
var user;
($('#login-btn')).click(function() {
navigator.id.request({
siteName: 'neighr'
});
return false;
});
($('#logout-btn')).click(function() {
navigator.id.logout();
return false;
});
user = window.currentUser;
if (!user) {
user = null;
}
return navigator.id.watch({
loggedInUser: window.currentUser,
onlogin: function(assertion) {
return $.ajax({
type: 'POST',
url: '/verify',
cache: false,
dataType: 'json',
data: {
assertion: assertion,
_csrf: window._csrf
},
success: function(res, status, xhr) {
if (res.redirect) {
return window.location = res.redirect;
} else {
return window.location.reload();
}
},
error: function(xhr, status, err) {
navigator.id.logout();
return alert("Login failure: " + err);
}
});
},
onlogout: function() {
return $.ajax({
type: 'POST',
url: '/logout',
data: {
_csrf: window._csrf
},
success: function(res, status, xhr) {
return window.location = '/';
},
error: function(xhr, status, err) {
return alert("Logout failure: " + err);
}
});
}
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment