Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

General updates, some modules added.

  • Loading branch information...
commit e4d237e1dcbb6f705ac75eca31d57216bc81426e 1 parent 7f6cb35
Ariel Falduto authored
1  .gitignore
View
@@ -14,4 +14,5 @@ attic
.Trashes
# Own generated
+config/runtime.json
public/stylesheets/bp.css
29 app.js
View
@@ -1,6 +1,6 @@
/**
- * Module dependencies.
+ * Generic node boilerplate.
*/
var
@@ -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)
@@ -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 config/default.yaml
View
@@ -0,0 +1,4 @@
+
+port: 3000
+
+verbose: true
2  config/production.yaml
View
@@ -0,0 +1,2 @@
+
+verbose: false
2  grunt.js
View
@@ -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: {
6 locales/en/translation.json
View
@@ -0,0 +1,6 @@
+
+{
+ "app": {
+ "message": "Hello sfrom nbp!"
+ }
+}
6 locales/es/translation.json
View
@@ -0,0 +1,6 @@
+
+{
+ "app": {
+ "message": "Hola desde nbp!"
+ }
+}
67 models/user.js
View
@@ -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 package.json
View
@@ -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",
2  views/index.jade
View
@@ -1,4 +1,4 @@
extends box
append box
- h2 Hello, from nbp!
+ h2= t('app.message')
Please sign in to comment.
Something went wrong with that request. Please try again.