-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ var require = { | |
baseUrl: "js", | ||
shim: { | ||
'jquery': { | ||
exports: 'jQuery' | ||
exports: 'jQuery', | ||
init: function() { | ||
this.jQuery.noConflict(); | ||
This comment has been minimized.
Sorry, something went wrong.
toolness
|
||
} | ||
} | ||
}, | ||
paths: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,17 @@ | |
defineTests(["browserid-ajax"], function(BrowserIDAjax) { | ||
module("browserid-ajax"); | ||
|
||
function FakeNavigatorID() { | ||
function FakeNavigatorID(assertion) { | ||
return { | ||
_options: null, | ||
get: function(cb) { | ||
this._options = {onlogin: cb}; | ||
watch: function(opts) { | ||
this._options = opts; | ||
}, | ||
request: function(opts) { | ||
this._options.onlogin(assertion); | ||
}, | ||
logout: function() { | ||
this._options.onlogout(); | ||
} | ||
}; | ||
} | ||
|
@@ -20,11 +26,33 @@ defineTests(["browserid-ajax"], function(BrowserIDAjax) { | |
}; | ||
} | ||
|
||
test("email sentinel values preserved", function() { | ||
var id = FakeNavigatorID(); | ||
|
||
var browserid = BrowserIDAjax({ | ||
email: null, /* not logged in */ | ||
id: id | ||
}); | ||
strictEqual(id._options.loggedInUser, null); | ||
|
||
browserid = BrowserIDAjax({ | ||
email: undefined, /* login status unknown */ | ||
id: id | ||
}); | ||
strictEqual(id._options.loggedInUser, undefined); | ||
|
||
browserid = BrowserIDAjax({ | ||
email: 'foo@bar.org', /* foo@bar.org logged in */ | ||
id: id | ||
}); | ||
equal(id._options.loggedInUser, 'foo@bar.org'); | ||
}); | ||
|
||
test("login error on failed verify works", function() { | ||
var loginErrorEvents = 0; | ||
var browserid = BrowserIDAjax({ | ||
email: '', | ||
id: FakeNavigatorID(), | ||
email: null, | ||
id: FakeNavigatorID('fake assertion for foo@bar.org'), | ||
verifyURL: '/verify', | ||
logoutURL: '/logout', | ||
csrfToken: 'fake csrf token', | ||
|
@@ -37,26 +65,25 @@ defineTests(["browserid-ajax"], function(BrowserIDAjax) { | |
|
||
equal(loginErrorEvents, 0); | ||
browserid.login(); | ||
browserid.id._options.onlogin('fake assertion for foo@bar.org'); | ||
equal(loginErrorEvents, 1); | ||
}); | ||
|
||
test("verification works", function() { | ||
var loginEvents = 0; | ||
var loginErrorEvents = 0; | ||
var browserid = BrowserIDAjax({ | ||
email: '', | ||
id: FakeNavigatorID(), | ||
email: null, | ||
id: FakeNavigatorID('fake assertion for foo@bar.org'), | ||
verifyURL: '/verify', | ||
logoutURL: '/logout', | ||
csrfToken: 'fake csrf token', | ||
network: FakeNetwork({ | ||
'POST /verify': function(options) { | ||
equal(options.data.assertion, 'fake assertion for foo@bar.org'); | ||
equal(options.headers['X-CSRFToken'], 'fake csrf token'); | ||
equal(options.headers['x-csrf-token'], 'fake csrf token'); | ||
equal(options.dataType, 'json'); | ||
options.success({ | ||
csrfToken: 'new fake csrf token', | ||
status: 'ok', | ||
email: 'foo@bar.org', | ||
}); | ||
} | ||
|
@@ -65,17 +92,11 @@ defineTests(["browserid-ajax"], function(BrowserIDAjax) { | |
.on('login:error', function() { loginErrorEvents++; }); | ||
|
||
equal(browserid.email, null); | ||
equal(browserid.csrfToken, 'fake csrf token'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stenington
Author
Owner
|
||
|
||
browserid.login(); | ||
browserid.id._options.onlogin(null); | ||
equal(loginEvents, 0, "null assertions don't trigger login events"); | ||
equal(loginErrorEvents, 1, "null assertions do trigger login:error evts"); | ||
browserid.id._options.onlogin('fake assertion for foo@bar.org'); | ||
|
||
equal(loginEvents, 1); | ||
equal(browserid.email, 'foo@bar.org'); | ||
equal(browserid.csrfToken, 'new fake csrf token'); | ||
}); | ||
|
||
test("logout works", function() { | ||
|
@@ -88,23 +109,21 @@ defineTests(["browserid-ajax"], function(BrowserIDAjax) { | |
csrfToken: 'fake csrf token', | ||
network: FakeNetwork({ | ||
'POST /logout': function(options) { | ||
equal(options.headers['X-CSRFToken'], 'fake csrf token'); | ||
equal(options.headers['x-csrf-token'], 'fake csrf token'); | ||
equal(options.dataType, 'json'); | ||
options.success({ | ||
csrfToken: 'another new fake csrf token', | ||
status: 'ok', | ||
email: null, | ||
}); | ||
} | ||
}) | ||
}).on('logout', function() { logoutEvents++; }); | ||
|
||
equal(browserid.email, 'foo@barf.org'); | ||
equal(browserid.csrfToken, 'fake csrf token'); | ||
|
||
browserid.logout(); | ||
|
||
equal(logoutEvents, 1); | ||
equal(browserid.email, null); | ||
equal(browserid.csrfToken, 'another new fake csrf token'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,14 @@ <h3><a class="brand" href="/"> | |
Help: {% if tooltips %}Off{% else %}On{% endif %} | ||
</a></li> | ||
</ul> | ||
{% if user %} | ||
<ul class="nav pull-right"> | ||
{% if user %} | ||
<li class="user">{{user.attributes.email}}</li> | ||
<li><a href="/backpack/signout">Sign Out</a></li> | ||
<li><a class="js-browserid-logout" href="#">Sign Out</a></li> | ||
{% else %} | ||
<li><a class="js-browserid-link" href="#">Sign In</a></li> | ||
{% endif %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -87,6 +89,39 @@ <h2>Legal</h2> | |
</div> | ||
|
||
<script src="//www.mozilla.org/tabzilla/media/js/tabzilla.js"></script> | ||
<script src="/js/require-config.js"></script> | ||
<script src="/js/require.min.js"></script> | ||
<script type="text/javascript"> | ||
require(['browserid-ajax'], function(BrowserIDAjax){ | ||
var browserid = BrowserIDAjax({ | ||
{% if user %} | ||
email: "{{ user.attributes.email }}", | ||
{% else %} | ||
email: null, | ||
{% endif %} | ||
verifyURL: '/backpack/authenticate', | ||
logoutURL: '/backpack/signout', | ||
csrfToken: '{{ csrfToken }}' | ||
}).on('login:error', function() { | ||
console.log('error'); | ||
This comment has been minimized.
Sorry, something went wrong.
toolness
|
||
}).on('login', function() { | ||
console.log('woot'); | ||
window.location.reload(); | ||
}).on('logout', function() { | ||
console.log('logout'); | ||
window.location.reload(); | ||
}).on('logout:error', function() { | ||
console.log('wat'); | ||
}); | ||
|
||
$('.js-browserid-link').bind('click', function(){ | ||
browserid.login(); | ||
}); | ||
$('.js-browserid-logout').bind('click', function(){ | ||
browserid.logout(); | ||
}); | ||
}); | ||
</script> | ||
{% block scripts %}{% endblock %} | ||
|
||
</body> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,9 @@ | ||
{% extends 'layout.html' %} | ||
{% block body %} | ||
<h1>Welcome</h1> | ||
<h2>Use the green button below to <a href="#" class="js-browserid-link">sign in.</a><br/> Don’t worry if you don’t have an account, that’ll get taken care of.</h2> | ||
|
||
<form class="signin js-browserid-form" method="POST" action="/backpack/authenticate"> | ||
<input class="js-browserid-input" name="assertion" type="hidden"></input> | ||
<input name="_csrf" type="hidden" value="{{ csrfToken }}"></input> | ||
</form> | ||
<h2>Use the blue button below to <a href="#" class="js-browserid-link">sign in.</a><br/> Don’t worry if you don’t have an account, that’ll get taken care of.</h2> | ||
|
||
<div style="padding-top: 10px"> | ||
<a class="js-browserid-link" href="#"><img src="https://browserid.org/i/sign_in_green.png"/></a> | ||
<a class="js-browserid-link" href="#"><img src="https://developer.mozilla.org/files/3957/email_sign_in_blue.png"/></a> | ||
</div> | ||
|
||
<script src="/js/require-config.js"></script> | ||
<script src="/js/require.min.js"></script> | ||
<script type="text/javascript"> | ||
require(['browserid-ajax', 'jquery'], function(BrowserIDAjax, $){ | ||
var browserid = BrowserIDAjax({ | ||
email: '', | ||
verifyURL: '/backpack/authenticate', | ||
logoutURL: '/backpack/signout', | ||
csrfToken: '{{ csrfToken }}' | ||
}).on('login:error', function() { | ||
console.log('error'); | ||
}).on('login', function() { | ||
console.log('woot'); | ||
window.location = '/'; | ||
}); | ||
|
||
$('.js-browserid-link').bind('click', function(){ browserid.login(); }); | ||
}); | ||
/*!!function loginHandler () { | ||
//begin login handler | ||
function launchBrowserId(callback) { | ||
return function() { navigator.id.get(callback, { | ||
siteName: 'Open Badge Backpack', | ||
termsOfService: '/tou.html', | ||
privacyPolicy: '/privacy.html', | ||
returnTo: '/' | ||
}); } | ||
} | ||
function handleResponse(assertion) { | ||
if (!assertion) return false; | ||
$('.js-browserid-input').val(assertion); | ||
$('.js-browserid-form').trigger('submit'); | ||
} | ||
$('.js-browserid-link').bind('click', launchBrowserId(handleResponse)); | ||
//begin login handler scope | ||
}(); | ||
*/ | ||
</script> | ||
{% endblock %} |
1 comment
on commit a46cee7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you should make sure you add a - phantomjs static/test/phantom-qunit.js http://localhost:8888/test/backpack/
entry to your .travis.yml
so the new tests are CI'd.
If we're adding
csrfToken
as a global context variable for templates, we should probably remove it as an explicitly passed-in variable from the controllers that pass it in, right?