Created
February 21, 2015 01:26
-
-
Save blizzarddreams/4a8d509a186380af6dab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| }); | |
| /*user.save(function(err, user) { | |
| if (err) return console.error(err); | |
| req.session.success = "Grats"; | |
| res.redirect('/'); | |
| }); */ | |
| res.redirect('/'); | |
| }); | |
| }); | |
| }); | |
| app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment