-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.js
129 lines (85 loc) · 3.04 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
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
const express = require('express')
// const { blogs, users } = require('./model/exp')
const { create,createBlog,createpageRender,SinglePageRender,Delete,editRender,edit, myblogsrender} = require('./Controller/blog/blogcontroller')
const { RenderRegister,CreateUser,RenderLogin, LoginUser, LogOut, Forgot } = require('./Controller/Auth/authController')
const app = express()
const bcrypt = require('bcrypt')
const { isAuthenticated } = require('./Middleware/isAuthenticated')
require('dotenv').config() //require or import dotenv with default configuration
const cookieParser = require('cookie-parser')
//database connection
require("./model/exp")
app.set("view engine", 'ejs')
//cookie bata aako data padhna lai middleware authenticaion ko lagi
app.use(cookieParser())
const session = require("express-session")
const flash = require("connect-flash")
app.use(session({
secret : "Iamaayush",
resave : false,
saveUninitialized: false
}))
app.use(flash())
//NAVBAR DYNamics ko lagi middleware banauney
app.use((req,res,next)=>{
res.locals.currentUser = req.cookies.token
next()
})
//nodelai File access garna dey vaneko
app.use(express.static("public/"))
app.use(express.static("uploads/"))
app.use(express.json()) // parse gaar or handel gaar vanya form bata aako data
app.use(express.urlencoded({extended:true}))
//multer image ko lagi import garya ho
const {multer, storage} = require("./Middleware/MulterConfig");
const { users } = require('./model/exp')
const sendEmail = require('./Services/Sendemail')
const catchError = require('./Services/catchError')
const upload = multer({storage : storage})
//main page render
app.get('/',create)
//createpagerender
app.get('/create', isAuthenticated, createpageRender)
// Single blog page render
app.get("/Single/:id", isAuthenticated, SinglePageRender)
app.get('/Delete/:id',isAuthenticated,Delete)
//database nma halna ko lagi
app.post('/create', catchError(isAuthenticated), upload.single("img"),createBlog)
//edit ko api banako
app.get('/edit/:id', isAuthenticated, editRender )
//edit gareko database ma halna ko lagi
app.post('/edit/:id', isAuthenticated, upload.single("img"), edit)
//register page ma render gar
app.get('/register',RenderRegister)
app.get('/myblog', isAuthenticated, myblogsrender)
//User lai data base ma halna ko lagi
app.post('/registerUser',catchError(CreateUser))
//Login page ma render gar
app.get('/login', RenderLogin)
//Login Garney yaha bata ho
app.post('/loginUser', LoginUser )
//logout ko
app.get('/logout', LogOut)
//forgot page render garya matra ho
app.get('/Forgot', Forgot)
//post for forgot
app.post('/forgotPass', async (req,res)=>{
const email = req.body.email
const checkUser = await users.findAll({
where :{
Email : email
}
})
if(!checkUser){
return res.send("Email with that user not foud")
}
await sendEmail({
email: email,
subject : "forget password otp",
otp : 1234,
})
res.send("email send successfully")
})
app.listen(3000, ()=>{
console.log("Server is running on port 3000")
})