Skip to content

Commit

Permalink
General updates, some modules added.
Browse files Browse the repository at this point in the history
  • Loading branch information
outaTiME committed Nov 13, 2012
1 parent 7f6cb35 commit e4d237e
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,4 +14,5 @@ attic
.Trashes

# Own generated
config/runtime.json
public/stylesheets/bp.css
29 changes: 22 additions & 7 deletions app.js
@@ -1,6 +1,6 @@

/**
* Module dependencies.
* Generic node boilerplate.
*/

var
Expand All @@ -18,25 +18,38 @@ var
routes = require('./routes'),
// user = require('./routes/user'),

// translation
i18n = require('i18next'),

// HTML5 Boilerplate
h5bp = require('h5bp');
h5bp = require('h5bp'),

config = require('config'),

var app = express();
// application
app = express();

i18n.init({
fallbackLng: 'en',
debug: config.verbose
});

// configuration
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('port', process.env.PORT || config.port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon(path.join(__dirname, "public", 'favicon.ico')));
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(app.router);
app.use(stylus.middleware({
src: path.join(__dirname),
dest: path.join(__dirname, "public"),
dest: path.join(__dirname, 'public'),
compile: function (str, path) {
return stylus(str)
.set('filename', path)
Expand All @@ -59,9 +72,11 @@ app.configure('development', function () {
app.use(express.errorHandler());
});

i18n.registerAppHelper(app);

app.get('/', routes.index);
// app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
console.log('Express server listening on port ' + app.get('port'));
});
4 changes: 4 additions & 0 deletions config/default.yaml
@@ -0,0 +1,4 @@

port: 3000

verbose: true
2 changes: 2 additions & 0 deletions config/production.yaml
@@ -0,0 +1,2 @@

verbose: false
2 changes: 1 addition & 1 deletion grunt.js
Expand Up @@ -4,7 +4,7 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
app: ['grunt.js', 'app.js', 'routes/**/*.js']
app: ['grunt.js', 'app.js', 'models/**/*.js', 'routes/**/*.js']
},
replace: {
dist: {
Expand Down
6 changes: 6 additions & 0 deletions locales/en/translation.json
@@ -0,0 +1,6 @@

{
"app": {
"message": "Hello sfrom nbp!"
}
}
6 changes: 6 additions & 0 deletions locales/es/translation.json
@@ -0,0 +1,6 @@

{
"app": {
"message": "Hola desde nbp!"
}
}
67 changes: 67 additions & 0 deletions models/user.js
@@ -0,0 +1,67 @@

/**
* User Schema.
*/

var
mongoose = require('mongoose'),
Schema = mongoose.Schema,
bcrypt = require('bcrypt'),
SALT_WORK_FACTOR = 10;

var UserSchema = new Schema({
username: {
type: String,
required: true,
index: {
unique: true
}
},
password: {
type: String,
required: true
},
role: {
type: String,
'default': 'user',
enum: [
'user',
'admin'
]
}
});

UserSchema.pre('save', function (next) {
var user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified('password')) {
return next();
}

// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, function (err, salt) {
if (err) {
return next(err);
}
// hash the password using our new salt
bcrypt.hash(user.password, salt, function (err, hash) {
if (err) {
return next(err);
}
// override the cleartext password with the hashed one
user.password = hash;
next();
});
});
});

UserSchema.methods.comparePassword = function (candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function (err, isMatch) {
if (err) {
return cb(err);
}
cb(null, isMatch);
});
};

module.exports = mongoose.model('User', UserSchema);
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -20,11 +20,16 @@
"start": "node app"
},
"dependencies": {
"express": "3.0.0rc5",
"express": "3.x",
"jade": "*",
"stylus": "*",
"nib": "*",
"h5bp": "*"
"h5bp": "*",
"mongoose": "3.x",
"bcrypt": "*",
"i18next": "1.x",
"config": "*",
"yaml": "*"
},
"devDependencies": {
"grunt": "~0.3.15",
Expand Down
2 changes: 1 addition & 1 deletion views/index.jade
@@ -1,4 +1,4 @@
extends box

append box
h2 Hello, from nbp!
h2= t('app.message')

0 comments on commit e4d237e

Please sign in to comment.