Skip to content

Instantly share code, notes, and snippets.

@blizzarddreams
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save blizzarddreams/545a2c2e4bd471d68668 to your computer and use it in GitHub Desktop.

Select an option

Save blizzarddreams/545a2c2e4bd471d68668 to your computer and use it in GitHub Desktop.
var express = require('express');
var mongoose = require('mongoose');
var bcrypt = require('bcrypt');
var bodyParser = require('body-parser');
mongoose.connect("mongodb://localhost/blog");
var userSchema = mongoose.Schema({
user: String,
pass: String,
hash: String
});
var blogSchema = mongoose.Schema({
title: String,
content: String,
when: {
type: Date,
default: Date.now
}
});
var User = mongoose.model('User', userSchema);
var Blog = mongoose.model('Blog', blogSchema);
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/views/login.html');
});
app.post('/', function(req, res) {
var user = req.body.user;
var pass = req.body.pass;
bcrypt.genSalt(20, function(err, salt) {
bcrypt.hash(pass, salt, function(err, hash) {
var user = new User({
user: user,
pass: pass,
hash: hash
}).save(function(err, user) {
if (err) console.error(err);
console.log('yay');
});
});
});
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment