-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
72 lines (58 loc) · 1.84 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var express = require("express")
var bodyParser = require("body-parser")
var User = require('./models/user').User
var app = express()
var cookiesSession = require("cookie-session")
var router_app = require("./routes_app")
var session_middleware = require("./middlewares/session")
var formidable = require("express-formidable")
var methodOverride = require("method-override")
app.use(express.static('public'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
app.use(methodOverride("_method"))
app.use(cookiesSession({
name: "session",
keys: ["llave-1","llave-2"]
}))
app.use(formidable({keepExtensions: true, uploadDir: true}))
app.set("view engine","jade")
app.get("/",function(req,res){
console.log(req.session.user_id)
res.render("index")
})
app.get("/signup",function(req,res){
User.find(function(err,doc){
console.log(doc)
res.render("signup")
})
})
app.get("/login",function(req,res){
res.render("login")
})
app.post("/user",function(req,res){
var user = new User({email: req.body.email,
password: req.body.password,
password_confirmation: req.body.password_confirmation,
username: req.body.username
})
user.save().then(function(us){
res.send('Guardamos el usuario exitosamente')
},function(err){
console.log(String(err))
res.send('Hubo un error al guardar los datos')
})
})
app.post("/sessions",function(req,res){
console.log("ESTOY AUI EN SESSIONS *********************************")
User.findOne({
email: req.body.email,
password:req.body.password
},function(err,user){
req.session.user_id = user._id
res.redirect("/app")
})
})
app.use("/app",session_middleware)
app.use("/app",router_app)
app.listen(3000)