Skip to content
Browse files

General updates, add user fixtures.

  • Loading branch information...
1 parent 856dd9f commit 92638ab6fb53a2cfbe643c9cd2fd18a1d899186f @outaTiME committed Nov 14, 2012
Showing with 96 additions and 39 deletions.
  1. +2 −1 .gitignore
  2. +24 −8 app.js
  3. +6 −0 fixtures/README.md
  4. +56 −0 fixtures/populate.js
  5. +1 −1 grunt.js
  6. +2 −1 package.json
  7. +1 −1 public/humans.txt
  8. +0 −16 public/stylesheets/nbp.css
  9. +0 −10 public/stylesheets/nbp/dialog.css
  10. +3 −0 stylesheets/nbp.styl
  11. +1 −1 views/login.jade
View
3 .gitignore
@@ -15,4 +15,5 @@ attic
# Own generated
config/runtime.json
-public/stylesheets/bp.css
+public/stylesheets/nbp.css
+public/stylesheets/nbp
View
32 app.js
@@ -38,6 +38,7 @@ var
i18n.init({
fallbackLng: 'en',
+ // ignoreRoutes: ['images/', 'javascripts/', 'stylesheets/'],
debug: config.verbose
});
@@ -49,14 +50,8 @@ app.configure(function () {
app.use(express.favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.logger('dev'));
app.use(express.bodyParser());
- app.use(i18n.handle);
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
- app.use(express.session());
- app.use(flash());
- app.use(passport.initialize());
- app.use(passport.session());
- app.use(app.router);
app.use(stylus.middleware({
src: path.join(__dirname),
dest: path.join(__dirname, 'public'),
@@ -68,6 +63,12 @@ app.configure(function () {
}
}));
app.use(express.static(path.join(__dirname, 'public')));
+ app.use(express.session());
+ app.use(flash());
+ app.use(passport.initialize());
+ app.use(passport.session());
+ app.use(i18n.handle);
+ app.use(app.router);
// bp
app.use(h5bp.ieEdgeChromeFrameHeader());
app.use(h5bp.protectDotfiles());
@@ -86,19 +87,33 @@ i18n.registerAppHelper(app);
// mongoose
-var
- mongoose = require('mongoose');
+var mongoose = require('mongoose');
mongoose.set('debug', config.verbose);
mongoose.connect(process.env.MONGOHQ_URL || config.database.uri);
+mongoose.connection.on('error', function (err) {
+ console.error('MongoDB error: ' + err.message);
+ console.error('Make sure a mongoDB server is running and accessible by this application');
+});
+
// passport
var
LocalStrategy = require('passport-local').Strategy,
User = require('./models/user');
+passport.serializeUser(function (user, done) {
+ done(null, user.id);
+});
+
+passport.deserializeUser(function (id, done) {
+ User.findById(id, function (err, user) {
+ done(err, user);
+ });
+});
+
passport.use(new LocalStrategy(
function (username, password, done) {
User.findOne({ username: username }, function (err, user) {
@@ -128,6 +143,7 @@ passport.use(new LocalStrategy(
app.get('/login', function (req, res) {
var user = req.user, message = req.flash('error');
+ console.info(message);
res.render('login', {
user: user,
message: message
View
6 fixtures/README.md
@@ -0,0 +1,6 @@
+How To Create Fixtures
+======================
+
+If you want to play with nbp use the following scripts to create the initial data:
+
+ > node fixtures/populate.js
View
56 fixtures/populate.js
@@ -0,0 +1,56 @@
+
+/**
+ * Populate.
+ */
+
+var
+
+ // configuration
+ config = require('config'),
+
+ // basic
+ async = require('async'),
+
+ // mongoose
+ mongoose = require('mongoose'),
+
+ // models
+ User = require('../models/user');
+
+// FIXME: Export to generic
+mongoose.set('debug', config.verbose);
+mongoose.connect(process.env.MONGOHQ_URL || config.database.uri);
+mongoose.connection.on('error', function (err) {
+ console.error('MongoDB error: ' + err.message);
+ console.error('Make sure a mongoDB server is running and accessible by this application');
+});
+
+var createUser = function (username, password, role, callback) {
+ console.log('Creating user "' + username + '"');
+ var user = new User({
+ username: username,
+ password: password
+ });
+ if (typeof role === "string") { // if no role default
+ user.role = role;
+ }
+ user.save(callback);
+};
+
+var createUsers = function (callback) {
+ async.parallel([
+ function (cb) { createUser('admin', 'admin', 'admin', cb); },
+ function (cb) { createUser('user', 'user', null, cb); }
+ ], callback);
+};
+
+async.series([createUsers], function (err) {
+ if (err) {
+ console.dir(err);
+ } else {
+ console.log('Population complete!');
+ }
+ setTimeout(function () {
+ mongoose.connection.close();
+ }, 1000);
+});
View
2 grunt.js
@@ -4,7 +4,7 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
- app: ['grunt.js', 'app.js', 'models/**/*.js', 'routes/**/*.js']
+ app: ['grunt.js', 'app.js', 'models/**/*.js', 'routes/**/*.js', 'fixtures/**/*.js']
},
replace: {
dist: {
View
3 package.json
@@ -32,7 +32,8 @@
"yaml": "*",
"passport": "*",
"passport-local": "*",
- "connect-flash": "*"
+ "connect-flash": "*",
+ "async": "*"
},
"devDependencies": {
"grunt": "~0.3.15",
View
2 public/humans.txt
@@ -12,7 +12,7 @@
From: Buenos Aires, Argentina
/* SITE */
- Last update: Tue Nov 13 2012 20:12:44
+ Last update: Wed Nov 14 2012 11:27:15
Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
Components: H5BP, Modernizr, jQuery, Twitter Bootstrap, LESS, Jade, Grunt
Software: Sublime Text 2, Photoshop
View
16 public/stylesheets/nbp.css
@@ -1,16 +0,0 @@
-@import "vendor/bootstrap.min.css";
-@import "vendor/bootstrap-responsive.min.css";
-body{background:url("/images/light_noise_diagonal.png") center top repeat;font-size:13px;line-height:18px}
-.touch *{-webkit-touch-callout:none;-webkit-text-size-adjust:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-o-user-select:none;-ms-user-select:none;user-select:none}
-.touch input,.touch textarea,.touch select{-webkit-user-select:auto;-khtml-user-select:auto;-moz-user-select:auto;-o-user-select:auto;-ms-user-select:auto;user-select:auto}
-.no-touch ::selection{color:#fff;background:#f676b2}
-.no-touch ::-moz-selection{color:#fff;background:#f676b2}
-#box{padding:18px;text-align:center;position:relative}
-#box .alert{padding:8px 14px}
-form{margin:0}
-.flex{display:-webkit-box;display:-moz-box;display:-ms-box;display:-ms-flexbox;display:box;-webkit-box-orient:vertical;-moz-box-orient:vertical;-ms-box-orient:vertical;box-orient:vertical;-webkit-box-align:center;-moz-box-align:center;-ms-box-align:center;box-align:center;-webkit-box-pack:center;-moz-box-pack:center;-ms-box-pack:center;box-pack:center;width:100%;height:100%;vertical-align:top}
-.vignette{display:block;position:absolute;left:0;top:0;right:0;bottom:0;background-image:-webkit-radial-gradient(50% 50%,rgba(255,255,255,0),rgba(0,0,0,0.2));background-image:-moz-radial-gradient(50% 50%,rgba(255,255,255,0),rgba(0,0,0,0.2));background-image:-ms-radial-gradient(50% 50%,rgba(255,255,255,0),rgba(0,0,0,0.2));background-image:-o-radial-gradient(50% 50%,rgba(255,255,255,0),rgba(0,0,0,0.2))}
-hr.soften{height:1px;background-image:-webkit-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.1),rgba(0,0,0,0));background-image:-moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.1),rgba(0,0,0,0));background-image:-ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.1),rgba(0,0,0,0));background-image:-o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.1),rgba(0,0,0,0));border:0}
-.effect3{position:relative}
-.effect3:before,.effect3:after{z-index:-1;position:absolute;content:"";bottom:15px;left:10px;width:50%;top:90%;max-width:300px;background:#777;-webkit-box-shadow:0 15px 10px #777;-moz-box-shadow:0 15px 10px #777;box-shadow:0 15px 10px #777;-webkit-transform:rotate(-3deg);-moz-transform:rotate(-3deg);-o-transform:rotate(-3deg);-ms-transform:rotate(-3deg);transform:rotate(-3deg)}
-.effect3:after{-webkit-transform:rotate(3deg);-moz-transform:rotate(3deg);-o-transform:rotate(3deg);-ms-transform:rotate(3deg);transform:rotate(3deg);right:10px;left:auto}
View
10 public/stylesheets/nbp/dialog.css
@@ -1,10 +0,0 @@
-#box{background:#fff;border:1px solid #ddd}
-form{margin:0}
-.login h2{font-size:22px;font-weight:300;margin-bottom:18px;margin-top:0}
-#box .wrapper{height:auto}
-form fieldset > div{margin-left:14px}
-form input{width:100%;margin-left:-14px}
-form .submit{margin-top:9px;height:30px;background-image:url("/images/small.spinner.gif");background-position:center;background-repeat:no-repeat}
-@media only screen and (-moz-min-device-pixel-ratio: 1.5),only screen and (-webkit-min-device-pixel-ratio: 1.5),only screen and (min-device-pixel-ratio: 1.5){form .submit{background-image:url("/images/small.spinner@x1.5.gif");background-size:16px 16px}
-}@media only screen and (-moz-min-device-pixel-ratio: 2),only screen and (-webkit-min-device-pixel-ratio: 2),only screen and (min-device-pixel-ratio: 2){form .submit{background-image:url("/images/small.spinner@x2.gif");background-size:16px 16px}
-}
View
3 stylesheets/nbp.styl
@@ -1,6 +1,8 @@
@import "vendor/bootstrap.min.css"
@import "vendor/bootstrap-responsive.min.css"
+@import 'nib/vendor'
+
body {
background: url("/images/light_noise_diagonal.png") center top repeat;
font-size: 13px;
@@ -49,6 +51,7 @@ body {
border: 1px solid #ddd; */
text-align: center;
position: relative;
+ border-radius: 4px
}
#box .wrapper {
View
2 views/login.jade
@@ -21,7 +21,7 @@ append box
div
.control-group
.controls
- input(name="username", type="text", placeholder="Username")
+ input(name="username", type="text", placeholder="Username", autofocus)
.control-group
.controls
input(name="password", type="password", placeholder="Password")

0 comments on commit 92638ab

Please sign in to comment.
Something went wrong with that request. Please try again.