-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
94 lines (71 loc) · 1.89 KB
/
code.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// const bp = require("body-parser");
const express = require("express");
const validator = require("express-validator");
const session = require("express-session");
const mysql = require("mysql");
const app = express();
const conn = mysql.createConnection({host:"localhost", user:"root", password:"", database:"vcf"});
app.use(express.urlencoded({extended:true}));
app.use(session({
secret: "somekey",
resave: false,
saveUninitialized:false
}))
app.set("view-engine", "ejs");
app.get("/account", (req, res) => {
res.render("index.ejs");
})
app.get("/", (req, res) => {
res.render("login.ejs");
});
app.post("/login", (req, res) => {
var username = req.body.username;
var password = req.body.password;
console.log(username, password);
res.render("index.ejs");
session.username = username;
});
app.get("/home", (req, res) => {
res.render("homepage/index.ejs");
})
app.post("/submit", (req, res) => {
var sql = "SELECT * FROM users";
conn.query(sql, (err, result)=>{
if(err){
console.log(err);
}
else{
res.render("data.ejs", {'users':result})
// for(var i = 0; i<result.length; i++){
// console.log(result[i].id,result[i].fullname, result[i].username, result[i].password, "");
// }
}
})
})
app.get("/a", (req, res)=>{
res.send(session.username);
})
app.get("/b", (req, res)=>{
res.send(session.username);
})
app.get("/c", (req, res)=>{
res.send(session.username);
})
app.get("/logout", (req, res)=>{
session.username = null;
res.send(session.username);
})
app.listen('3000', (err)=>{
if(!err){
console.log("Server Started");
}
if(conn.connect((err) => {
if(err){
console.log("error");
console.log(err);
}
else{
console.log("connected")
}
}));
})