-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (62 loc) · 1.68 KB
/
index.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
const userSchema = require('./schemas/userSchema');
require('dotenv').config()
const express = require('express'),
app = express(),
mongoose = require('mongoose'),
session = require("cookie-session"),
bodyParser = require('body-parser'),
ejs = require('ejs'),
url = require('url');
const port = process.env.PORT || 9000;
app.use(bodyParser.json({
parameterLimit: 100000,
limit: '50mb'
}));
app.use(bodyParser.urlencoded({
parameterLimit: 100000,
limit: '50mb',
extended: true
}));
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.render('index');
});
app.get('/register', (req, res) => {
res.render('register');
});
app.post('/register/', async (req, res) => {
var user = userSchema({
email: req.body.email,
password: req.body.password,
});
await user.save()
res.redirect('/login/{"email":"' + req.body.email + '", "password":"' + req.body.password + '"}');
});
app.get('/login/:email', async (req, res) => {
try {
console.log(req.params.email)
var email = JSON.parse(req.params.email);
console.log(email)
var user;
try {
user = await userSchema.find(email)
} catch (err) {
console.log(err)
}
console.log(user)
res.send(user);
} catch (err) {
console.log(err)
res.send(err.toString());
}
});
mongoose.set("strictQuery", false)
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log("Connected to Mongo DB")
})
app.listen(port, () => {
console.log(`TS Encryptid listening at http://localhost:${port}`)
});