-
-
Save scan/5940127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
($ '#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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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