Permalink
Browse files

Add export project feature.

  • Loading branch information...
1 parent d7f0573 commit e1c463410ec56a65b5c32a2e2209d40cc1b46375 Karthik Viswanathan committed Aug 28, 2012
Showing with 942 additions and 12 deletions.
  1. +1 −0 .nodemonignore
  2. +4 −0 export/base-app/Makefile
  3. +11 −0 export/base-app/app.js
  4. 0 export/base-app/lib/.gitignore
  5. +50 −0 export/base-app/lib/auth.js
  6. +13 −0 export/base-app/lib/utils.js
  7. +21 −0 export/base-app/package.json
  8. 0 export/base-app/public/images/.gitignore
  9. BIN export/base-app/public/images/persona.png
  10. 0 export/base-app/public/javascripts/.gitignore
  11. +5 −0 export/base-app/public/javascripts/.jshintrc
  12. +14 −0 export/base-app/public/javascripts/login.js
  13. +9 −0 export/base-app/public/stylesheets/bootstrap-2.0.4.min.css
  14. +9 −0 export/base-app/public/stylesheets/bootstrap-responsive-2.0.4.min.css
  15. +148 −0 export/base-app/public/stylesheets/styles.styl
  16. +72 −0 export/base-app/routes/index.js
  17. +60 −0 export/base-app/settings.js
  18. 0 export/base-app/test/.gitignore
  19. +10 −0 export/base-app/views/auth-required.jade
  20. +5 −0 export/base-app/views/index.jade
  21. +14 −0 export/base-app/views/layout.jade
  22. +5 −0 export/base-app/views/not-found.jade
  23. +444 −0 export/index.js
  24. +4 −0 package.json
  25. +6 −0 public/javascripts/controllers/project.js
  26. +3 −0 public/stylesheets/bootstrap-stripped.css
  27. +1 −1 public/stylesheets/bootstrap-stripped.min.css
  28. +3 −0 public/stylesheets/main.styl
  29. +12 −0 routes/index.js
  30. +4 −0 todo.txt
  31. +1 −1 views/helpers/share-login-form.jade
  32. +3 −2 views/templates/collections/project.jade
  33. +1 −7 views/templates/lists/form-element.jade
  34. +1 −1 views/templates/lists/navigation-element.jade
  35. +7 −0 views/templates/wrappers/form.jade
  36. +1 −0 views/templates/wrappers/navigation.jade
View
@@ -2,3 +2,4 @@
.*.swp
.*.swo
.*.swn
+/export/*
View
@@ -0,0 +1,4 @@
+test:
+ @./node_modules/.bin/mocha --reporter list
+
+.PHONY: test
View
@@ -0,0 +1,11 @@
+"use strict";
+var express = require('express');
+var app = express();
+
+var nconf = require('nconf');
+nconf.argv().env().file({ file: 'local.json' });
+
+require('./settings')(app, express, nconf);
+require('./routes')(app, nconf);
+
+app.listen(process.env.PORT || nconf.get('port'));
No changes.
@@ -0,0 +1,50 @@
+var request = require('request');
+
+/* Browser ID authentication
+ * Requires: web request, nconf
+ * Returns: A browser Id email if successful
+ */
+exports.verify = function(req, nconf, callback) {
+ var authUrl = nconf.get('authUrl') + '/verify';
+ var siteUrl = nconf.get('domain') + ':' + nconf.get('port');
+
+ if (!req.body.bid_assertion) {
+ callback(new Error('BrowserID assertion not found.'));
+ return;
+ }
+
+ var qs = {
+ assertion: req.body.bid_assertion,
+ audience: siteUrl
+ };
+
+ var params = {
+ url: authUrl,
+ form: qs
+ };
+
+ request.post(params, function(err, resp, body) {
+ var email = false;
+
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ try {
+ var jsonResp = JSON.parse(body);
+ if (jsonResp.status === 'okay') {
+ email = jsonResp.email;
+ } else {
+ // Response status is 'not okay'
+ callback(jsonResp);
+ return;
+ }
+ } catch (err) {
+ callback(err);
+ return;
+ }
+
+ callback(null, email);
+ });
+};
@@ -0,0 +1,13 @@
+/**
+ * Render a 404 response page.
+ *
+ * @param request - the web request object
+ * @param response - the web response object
+ */
+exports.render404 = function(request, response) {
+ response.status(404);
+ response.render('not-found', { path: request.path });
+};
+
+// no operation placeholder for empty callbacks
+exports.noOperation = function() {};
@@ -0,0 +1,21 @@
+{
+ "name": "appname",
+ "version": "0.0.1",
+ "engines": {
+ "node": ">= 0.6.19",
+ "npm": ">= 1.1.x"
+ },
+ "dependencies": {
+ "client-sessions": "0.0.8",
+ "connect": "2.4.3",
+ "express": "3.0.0rc3",
+ "jade": "0.27.2",
+ "nconf": "0.6.0",
+ "request": "2.9.153",
+ "stylus": "0.27.2"
+ },
+ "devDependencies": {
+ "mocha": "1.3.2",
+ "should": "1.1.0"
+ }
+}
No changes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,5 @@
+{
+ "node": true,
+ "strict": false,
+ "esnext": true
+}
@@ -0,0 +1,14 @@
+$(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();
+ }
+ });
+ });
+});

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,148 @@
+/* CSS-only Persona button - credits to Sawyer Hollenshead */
+/* http://dev.sawyerhollenshead.com/mozilla/buttons/buttons.html */
+.persona-button
+ color #fff
+ display inline-block
+ line-height 1
+ overflow hidden
+ position relative
+ text-decoration none
+ text-shadow 0 1px rgba(0,0,0,0.5), 0 0 2px rgba(0,0,0,0.2)
+
+ background #ee731a
+ background -moz-linear-gradient(top, #ee731a, #d03116)
+ background -ms-linear-gradient(top, #ee731a, #d03116)
+ background -o-linear-gradient(top, #ee731a, #d03116)
+ background -webkit-linear-gradient(top, #ee731a, #d03116)
+ background linear-gradient(top, #ee731a, #d03116)
+
+ -moz-border-radius 3px
+ -ms-border-radius 3px
+ -o-border-radius 3px
+ -webkit-border-radius 3px
+ border-radius 3px
+
+ -moz-box-shadow 0 1px 0 rgba(0,0,0,0.2)
+ -ms-box-shadow 0 1px 0 rgba(0,0,0,0.2)
+ -o-box-shadow 0 1px 0 rgba(0,0,0,0.2)
+ -webkit-box-shadow 0 1px 0 rgba(0,0,0,0.2)
+ box-shadow 0 1px 0 rgba(0,0,0,0.2)
+
+.persona-button:hover
+ color #fff
+ background #cb6216
+ background -moz-linear-gradient(top, #cb6216, #b12a13)
+ background -ms-linear-gradient(top, #cb6216, #b12a13)
+ background -o-linear-gradient(top, #cb6216, #b12a13)
+ background -webkit-linear-gradient(top, #cb6216, #b12a13)
+ background linear-gradient(top, #cb6216, #b12a13)
+
+.persona-button:active, .persona-button:focus
+ top 1px
+ -moz-box-shadow none
+ -ms-box-shadow none
+ -o-box-shadow none
+ -webkit-box-shadow none
+ box-shadow none
+
+.persona-button span
+ display inline-block
+ padding 5px 10px 5px 40px
+
+/* Icon */
+.persona-button span:after
+ background url(../images/persona.png) 10px center no-repeat
+ content ''
+ display block
+ width 31px
+
+ position absolute
+ bottom 0
+ left -3px
+ top 0
+ z-index 10
+
+/* Icon background */
+.persona-button span:before
+ content ''
+ display block
+ height 100%
+ width 20px
+
+ position absolute
+ bottom 0
+ left 0
+ top 0
+ z-index 1
+
+ background #e84a21
+ background -moz-linear-gradient(top, #f7ad27, #e84a21)
+ background -ms-linear-gradient(top, #f7ad27, #e84a21)
+ background -o-linear-gradient(top, #f7ad27, #e84a21)
+ background -webkit-linear-gradient(top, #f7ad27, #e84a21)
+ background linear-gradient(top, #f7ad27, #e84a21)
+
+ -moz-border-radius 3px 0 0 3px
+ -ms-border-radius 3px 0 0 3px
+ -o-border-radius 3px 0 0 3px
+ -webkit-border-radius 3px 0 0 3px
+ border-radius 3px 0 0 3px
+
+/* Triangle */
+.persona-button:before
+ background #42a9dd
+ content ''
+ display block
+ height 26px
+ width 26px
+
+ position absolute
+ left 2px
+ top 50%
+ margin-top -13px
+ z-index 0
+
+ background #e84a21
+ background -moz-linear-gradient(-45deg, #f7ad27, #e84a21)
+ background -ms-linear-gradient(-45deg, #f7ad27, #e84a21)
+ background -o-linear-gradient(-45deg, #f7ad27, #e84a21)
+ background -webkit-linear-gradient(-45deg, #f7ad27, #e84a21)
+ background linear-gradient(-45deg, #e84a21, #f7ad27)
+
+ -moz-box-shadow 1px -1px 1px rgba(0,0,0,0.1)
+ -ms-box-shadow 1px -1px 1px rgba(0,0,0,0.1)
+ -o-box-shadow 1px -1px 1px rgba(0,0,0,0.1)
+ -webkit-box-shadow 1px -1px 1px rgba(0,0,0,0.1)
+ box-shadow 1px -1px 1px rgba(0,0,0,0.1)
+
+ -moz-transform rotate(45deg)
+ -ms-transform rotate(45deg)
+ -o-transform rotate(45deg)
+ -webkit-transform rotate(45deg)
+ transform rotate(45deg)
+
+/* Inset shadow (required here because the icon background clips it when on the `a` element) */
+.persona-button:after
+ content ''
+ display block
+ height 100%
+ width 100%
+
+ position absolute
+ left 0
+ top 0
+ bottom 0
+ right 0
+ z-index 10
+
+ -moz-border-radius 3px
+ -ms-border-radius 3px
+ -o-border-radius 3px
+ -webkit-border-radius 3px
+ border-radius 3px
+
+ -moz-box-shadow inset 0 -1px 0 rgba(0,0,0,0.3)
+ -ms-box-shadow inset 0 -1px 0 rgba(0,0,0,0.3)
+ -o-box-shadow inset 0 -1px 0 rgba(0,0,0,0.3)
+ -webkit-box-shadow inset 0 -1px 0 rgba(0,0,0,0.3)
+ box-shadow inset 0 -1px 0 rgba(0,0,0,0.3)
@@ -0,0 +1,72 @@
+// persona-powered authentication
+var auth = require('../lib/auth');
+
+/**
+ * Creates the routes for the given express application.
+ *
+ * @param app - the express application
+ * @param nconf - the configuration settings
+ */
+module.exports = function(app, nconf) {
+ {{#screenList}}
+ app.get('/{{titleSlug}}', function(request, response) {
+ {{#if secure}}
+ if (request.session.email) {
+ response.render('{{titleSlug}}', {
+ session: request.session
+ });
+ } else {
+ response.render('auth-required', {
+ session: request.session
+ });
+ }
+ {{else}}
+ response.render('{{titleSlug}}', {
+ session: request.session
+ });
+ {{/if}}
+ });
+ {{/screenList}}
+
+ app.get('/', function(request, response) {
+ response.render('index', {
+ domain: nconf.get('domain'),
+ port: nconf.get('port')
+ });
+ });
+
+ // Log in route
+ app.post('/log-in', function(request, response) {
+ auth.verify(request, nconf, function(error, email) {
+ if (error) {
+ throw error;
+ }
+
+ if (email) {
+ // store the e-mail in the client session
+ request.session.email = email;
+ response.redirect(303, getRedirect(request));
+ } else {
+ throw new Error('Auth failed to return e-mail.');
+ }
+ });
+ });
+
+ // Log out route
+ app.get('/log-out', function(request, response) {
+ if (request.session) {
+ request.session.reset();
+ }
+
+ response.redirect(303, getRedirect(request));
+ });
+
+ /**
+ * Finds which URL to redirect to given a request.
+ */
+ function getRedirect(request) {
+ var redirect = request.query.redirect;
+ redirect = redirect || request.headers.referer;
+ return redirect || '/'; // default to home page
+ }
+};
Oops, something went wrong.

0 comments on commit e1c4634

Please sign in to comment.