Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed tests; updated persona api; error text updates

  • Loading branch information...
commit a5540c8b726e7eda82ca9e6866805b2341d94720 1 parent 107c95c
Jen Fong-Adwent authored
View
14 export/base-app/public/javascripts/login.js
@@ -1,14 +0,0 @@
-$(function() {
- // persona login
- $('.login-form a').click(function(event) {
- event.preventDefault();
- var $form = $(this).parent();
-
- navigator.id.getVerifiedEmail(function(assertion) {
- if (assertion) {
- $form.find('input[name="bid_assertion"]').val(assertion);
- $form.submit();
- }
- });
- });
-});
View
2  export/index.js
@@ -327,7 +327,7 @@ function renderElementTemplate(template, element, component, screensById) {
if (startMatch !== null) {
var startIndex = startMatch.index + startMatch[0].length;
var whitespace = startMatch[1];
-
+
// same amount of whitespace precedes 'else'
var endMatch = new RegExp('^' + whitespace + 'else', 'm').exec(template);
View
10 lib/authenticate.js
@@ -1,20 +1,20 @@
var request = require('request');
-/* Browser ID authentication
+/* Persona authentication
* Requires: web request, nconf
- * Returns: A browser Id email if successful
+ * Returns: A Persona email if successful
*/
exports.verify = function(req, nconf, callback) {
var authUrl = nconf.get('authUrl') + '/verify';
var siteUrl = nconf.get('domain') + ':' + nconf.get('authPort');
- if (!req.body.bid_assertion) {
- callback(new Error('BrowserID assertion not found.'));
+ if (!req.body.assertion) {
+ callback(new Error('Persona assertion not found.'));
return;
}
var qs = {
- assertion: req.body.bid_assertion,
+ assertion: req.body.assertion,
audience: siteUrl
};
View
28 lib/elements.js
@@ -90,7 +90,7 @@ function validateElement(req, beingCreated, db, callback) {
callback("Element's nextId must be an integer.");
return;
}
-
+
if (required !== undefined) {
if (required === 'true') {
body.required = required = true;
@@ -103,7 +103,7 @@ function validateElement(req, beingCreated, db, callback) {
return;
}
}
-
+
if (name !== undefined) {
if (typeof name !== 'string') {
callback("Element's name must be a string.");
@@ -113,7 +113,7 @@ function validateElement(req, beingCreated, db, callback) {
return;
}
}
-
+
if (text !== undefined) {
if (typeof text !== 'string') {
callback("Element's text must be a string.");
@@ -123,7 +123,7 @@ function validateElement(req, beingCreated, db, callback) {
return;
}
}
-
+
if (level !== undefined) {
if (typeof level === 'string') {
body.level = level = parseInt(level, 10);
@@ -150,11 +150,11 @@ function validateElement(req, beingCreated, db, callback) {
getScreensById(req, db, function(err, screensById) {
if (err) {
throw err;
- }
-
- if (!screensById[redirect]) {
- callback("Element's redirect must correspond to a real screen.");
- failedCallback = true;
+ } else {
+ if (!screensById[redirect]) {
+ callback("Element's redirect must correspond to a real screen.");
+ failedCallback = true;
+ }
}
});
@@ -176,11 +176,11 @@ function validateElement(req, beingCreated, db, callback) {
getScreensById(req, db, function(err, screensById) {
if (err) {
throw err;
- }
-
- if (!screensById[screen]) {
- callback("Element's screen must correspond to a real screen.");
- failedCallback = true;
+ } else {
+ if (!screensById[screen]) {
+ callback("Element's screen must correspond to a real screen.");
+ failedCallback = true;
+ }
}
});
View
43 public/javascripts/scripts/core.js
@@ -1,9 +1,50 @@
-require(['jquery'], function($) {
+require(['jquery', 'https://login.persona.org/include.js'], function($) {
$(function() {
var $window = $(window);
var $body = $('body');
var $sidebar = $('#sidebar');
+ // Persona login
+ /* Authenticatication for Persona */
+ $sidebar.on('click', 'a.login', function(event) {
+ event.preventDefault();
+ navigator.id.request();
+ });
+
+ $sidebar.on('click', 'a.log-out', function(event) {
+ event.preventDefault();
+ navigator.id.logout();
+ });
+
+ navigator.id.watch({
+ loggedInEmail: currentUser,
+ onlogin: function(assertion) {
+ $.ajax({
+ type: 'POST',
+ url: '/log-in',
+ data: { assertion: assertion },
+ success: function(res, status, xhr) {
+ window.location = redirectUrl;
+ },
+ error: function(res, status, xhr) {
+ alert('login failure ' + res);
+ }
+ });
+ },
+ onlogout: function() {
+ $.ajax({
+ type: 'POST',
+ url: '/log-out',
+ success: function(res, status, xhr) {
+ window.location.reload();
+ },
+ error: function(res, status, xhr) {
+ console.log('logout failure ' + res);
+ }
+ });
+ }
+ });
+
// placeholder polyfill
var input = document.createElement('input');
if (!('placeholder' in input)) {
View
26 public/javascripts/scripts/example.js
@@ -2,23 +2,21 @@ require.config({
baseUrl: '/javascripts/'
});
-require(['jquery', 'lib/bootstrap.min', 'https://browserid.org/include.js'], function($) {
+require(['scripts/core', 'lib/bootstrap.min']);
+
+require(['jquery', 'lib/bootstrap.min'], function($) {
$(function() {
- var $body = $('body');
- var $loginForm = $('header .login-form');
var $sidebar = $('#sidebar');
- // Browser ID login
- $loginForm.on('click', 'a', function(event) {
- event.preventDefault();
- navigator.id.getVerifiedEmail(function(assertion) {
- if (assertion) {
- $loginForm.find('input[name="bid_assertion"]').val(assertion);
- $loginForm.submit();
- }
- });
+ /* Authenticatication for Persona */
+ $sidebar.on('click', 'a.login', function(event) {
+ event.preventDefault();
+ navigator.id.request();
+ });
+
+ $sidebar.on('click', 'a.log-out', function(event) {
+ event.preventDefault();
+ navigator.id.logout();
});
});
});
-
-require(['scripts/core', 'lib/bootstrap.min']);
View
17 public/javascripts/scripts/not-found.js
@@ -2,21 +2,4 @@ require.config({
baseUrl: '/javascripts/'
});
-require(['jquery', 'https://browserid.org/include.js'], function($) {
- $(function() {
- var $loginForm = $('header .login-form');
-
- // Browser ID login
- $loginForm.on('click', 'a', function(event) {
- event.preventDefault();
- navigator.id.getVerifiedEmail(function(assertion) {
- if (assertion) {
- $loginForm.find('input[name="bid_assertion"]').val(assertion);
- $loginForm.submit();
- }
- });
- });
- });
-});
-
require(['scripts/core']);
View
23 public/javascripts/scripts/share-login.js
@@ -1,16 +1,17 @@
-require(['jquery', 'https://browserid.org/include.js'], function($) {
+require(['jquery', 'https://login.persona.org/include.js'], function($) {
$(function() {
- // Browser ID login
- $('#content').on('click', '.login-form a', function(event) {
- event.preventDefault();
- var $form = $(this).parent();
+ var $content = $('#content');
- navigator.id.getVerifiedEmail(function(assertion) {
- if (assertion) {
- $form.find('input[name="bid_assertion"]').val(assertion);
- $form.submit();
- }
- });
+ /* Authenticatication for Persona */
+ $content.on('click', 'a.login', function(event) {
+ event.preventDefault();
+ redirectUrl = $(this).data('redirect');
+ navigator.id.request();
+ });
+
+ $content.on('click', 'a.log-out', function(event) {
+ event.preventDefault();
+ navigator.id.logout();
});
});
});
View
6 routes/auth.js
@@ -22,7 +22,7 @@ module.exports = function(app, nconf, db) {
}
req.session.id = id;
- res.redirect('/');
+ res.json({ message: 'Login successful' });
});
}
});
@@ -51,12 +51,12 @@ module.exports = function(app, nconf, db) {
});
// Log out of napkin
- app.get('/log-out', function(req, res) {
+ app.post('/log-out', function(req, res) {
if (req.session) {
req.session.reset();
}
- res.redirect('/', 303);
+ res.json({ message: 'Log out successful' });
});
// Log out of project
View
4 test/test.authenticate.js
@@ -25,7 +25,7 @@ describe('login', function() {
var params = {
body: {
- bid_assertion: qs.assertion
+ assertion: qs.assertion
}
};
@@ -47,7 +47,7 @@ describe('login', function() {
var params = {
body: {
- bid_assertion: qs.assertion
+ assertion: qs.assertion
}
};
View
21 test/test.screens.js
@@ -91,17 +91,14 @@ describe('screen', function() {
it('accepts an empty callback', function(done) {
var req = otherScreenReq;
- screens.add(req, db);
-
- // wait 10ms for db transaction to complete
- setTimeout(function() {
+ screens.add(req, db, function(err) {
screens.get(req, db, 2, function(err, screen) {
screen.title.should.equal(req.body.title);
screen.isStart.should.equal(req.body.isStart);
screen.layout.should.equal(req.body.layout);
done();
});
- }, 10);
+ });
});
});
@@ -154,15 +151,12 @@ describe('screen', function() {
it('accepts an empty callback', function(done) {
req.body.title = 'My Screen3';
- screens.update(req, db, 1);
-
- // wait 10ms for db transaction to complete
- setTimeout(function() {
+ screens.update(req, db, 1, function(err) {
screens.get(req, db, 1, function(err, screen) {
screen.title.should.equal(req.body.title);
done();
});
- }, 10);
+ });
});
});
@@ -177,15 +171,12 @@ describe('screen', function() {
});
it('accepts an empty callback', function(done) {
- screens.remove(req, db, 2);
-
- // wait 10ms for db transaction to complete
- setTimeout(function() {
+ screens.remove(req, db, 2, function(err) {
screens.list(req, db, function(err, screenList) {
screenList.should.eql([]);
done();
});
- }, 10);
+ });
});
it('deletes a component associated with a screen', function(done) {
View
8 views/helpers/share-login-form.jade
@@ -2,8 +2,6 @@
<% redirect = ''; %>
<% } %>
-form.login-form(method='post',
- action!="/share/#{userId}/project/#{projectId}/screen/#{screenId}/log-in?redirect=<%- redirect %>")
- a.persona-button.share-element.auth(href='#log-in')
- span Sign in
- input(type='hidden', name='bid_assertion', value='1')
+a.persona-button.share-element.auth.login(href='#log-in',
+ data-redirect!="/share/#{userId}/project/#{projectId}/screen/<%- redirect %>")
+ span Sign in
View
14 views/layout.jade
@@ -23,13 +23,11 @@ html
if typeof(sharing) === 'undefined' || !sharing
if session.email
- a.persona-button.log-out(href='/log-out', tabindex='-1')
+ a.persona-button.log-out(href='#', tabindex='-1')
span Sign out
else
- form.login-form(method='post', action='/log-in')
- a.persona-button(href='#log-in', tabindex='-1')
- span Sign in
- input(type='hidden', name='bid_assertion', value='1')
+ a.persona-button.login(href='#log-in', tabindex='-1')
+ span Sign in
block github
iframe#fork(src='http://ghbtns.com/github-btn.html?user=mozilla&repo=napkin&type=fork&count=true',
@@ -42,5 +40,9 @@ html
#content
block content
-
+ script(type='text/javascript')
+ var currentUser = null;
+ var redirectUrl = '/';
+ if session.email
+ != '<script type="text/javascript">currentUser = "' + session.email + '";</script>'
block scripts
View
2  views/not-found.jade
@@ -4,7 +4,7 @@ block sidebar
a.btn.btn-danger#back(href='/') &larr; Back to home
h2 Not Found
- p The page you were looking for was not found. Please return to known territory by using your browser's back button or clicking the home link above.
+ p The page you were looking for was not found.
block scripts
script(src='/javascripts/lib/require-jquery.min.js', data-main='/javascripts/scripts/not-found.js')
Please sign in to comment.
Something went wrong with that request. Please try again.