-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
139 lines (92 loc) · 3.89 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const express = require("express")
<<<<<<< HEAD
const mysql = require("mysql")
const bcrypt = require("bcrypt")
const user = require("./reg.js")
const test = require("./mail")
const forgotPassword = require('./forgetPassword.js')
const app = express()
const bodyparser = require('body-parser');
const validator = require('./validation/validators')
// const forget = require('./forgetPass')
app.use(bodyparser.urlencoded({ extended: true }));
app.post('/register', (req, res) => {
// validator(req, res)
res.send("req validated")
const reg = user(req.body.email, req.body.password, req.body.role, req.body.is_enabled)
});
app.post('/passwordreset', (req, res) => {
forgotPassword(req.body.email,req.body.password)
res.send('password updated')
// const resetPassword = forgotPassword(req.body.email, req.body.password)
var d = new Date()
var timeObj = { hour: d.getHours(), minutes: d.getMinutes(), seconds: d.getSeconds() }
console.log(`H: ${timeObj.hour} M: ${timeObj.minutes} S: ${timeObj.seconds}`)
//res.send("passreset")
});
app.post('/mailrout', (req, res) => {
test(req.body)
res.status(200).json({
db: 'db updated and timeStamp created',
mail: 'mail sent'
})
})
app.listen(8000, function () {
console.log("listening on port 8000")
=======
const dotenv = require('dotenv')
const bodyParser = require('body-parser')
const connect = require('./dbconnect.js')
const authRoute = require('./auth.js')
const app = express()
dotenv.config()
app.use(bodyParser.urlencoded({extended : true}))
app.use(bodyParser.json())
app.use('/api/user', authRoute)
const table1 = 'CREATE TABLE IF NOT EXISTS users(id INT AUTO_INCREMENT PRIMARY KEY,email VARCHAR(255),password VARCHAR(50),role ENUM("user","admin"),deleted_at TIMESTAMP,is_enabled TIMESTAMP)ENGINE=INNODB'
connect.query(table1, function (error, result) {
if (error) {
console.log(error.message)
} else
console.log("table1 created")
})
const sql1 = "INSERT INTO users(id,email,password,role,deleted_at, is_enabled) VALUES(NULL, '[email protected]', 'mike07', 'user', 0.00, 0.00)"
connect.query(sql1, function(error, result){
if(error) {
console.log(error)
}
console.log("inserted number of rows in table1:" + result.affectedRows)
})
const table2 = "CREATE TABLE IF NOT EXISTS project(id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, name VARCHAR(255), description TEXT, token VARCHAR(255), created_at TIMESTAMP, updated_at TIMESTAMP, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE)ENGINE=INNODB"
connect.query(table2, function (error, result) {
if (error) {
console.log(error.message)
} else
console.log("table2 created!")
})
const sql2 = "INSERT INTO project(id,user_id,name,description,token,created_at,updated_at) VALUES(NULL, 1, 'mike', 'hdskuhfdbjkds', 'favfhdje56', 0.00,0.00)"
connect.query(sql2, function(error,result){
if(error) {
console.log(error)
}
console.log("inserted number of rows in table2:" + result.affectedRows)
})
const table3 = "CREATE TABLE IF NOT EXISTS post(id INT AUTO_INCREMENT PRIMARY KEY,user_id INT,project_id INT, title VARCHAR(100), body TEXT, published TIMESTAMP, created_at TIMESTAMP, updated_at TIMESTAMP, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY(project_id) REFERENCES project(id) ON DELETE CASCADE)ENGINE=INNODB"
connect.query(table3, function (error, result) {
if (error) {
console.log(error.message)
} else {
console.log("table3 created")
}
})
const sql3 = "INSERT INTO post(id,user_id,project_id,title,body,published,created_at,updated_at) VALUES(NULL,1, 1, 'headlesscms', 'cdhgsjkhlkjl',0.00, 0.00,0.00)"
connect.query(sql3, function(error,result){
if(error) {
console.log(error)
}
console.log("inserted number of rows in table3:" + result.affectedRows)
})
app.listen(8000, function () {
console.log("listening on port 8000")
>>>>>>> upstream/master
})