-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (73 loc) · 2.02 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
require('dotenv').config()
const express = require('express') //importing express
const app = express() //Making a new express app
const PORT = 80
const parser = require('body-parser')
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.API_KEY);
const { auth, requiresAuth } = require('express-openid-connect');
app.use(parser.urlencoded({ extended: false }))
app.use(parser.json())
app.set('view engine', 'ejs') //View engine or knows as front-end set to ejs
const config = {
authRequired: false,
auth0Logout: true,
secret: process.env.SECRET,
baseURL: process.env.BASE_URL,
clientID: process.env.CLIENT_ID,
issuerBaseURL: process.env.ISSUER
};
app.use(auth(config));
//Main page
app.get('/', (req, res) => {
const accept = req.oidc.isAuthenticated()
res.render('index', {
accept: accept
})
})
app.get('/login', (req, res) => {
res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out');
});
app.get('/profile', requiresAuth(), (req, res) => {
const user = req.oidc.user
res.render('profile', {
user: user
})
});
app.post('/success', (req, res) => {
const info = req.oidc.user
console.log(info.name,
req.body.name,
req.body.long)
const msg = {
to: info.name,
from: 'support@healthpro.ml',
subject: 'Confirmation',
text: 'This is a confirmation email saying that your form is submitted successfully. Our team will get back to you soon!',
}
sgMail
.send(msg)
.then(() => {
console.log('Email sent')
})
.catch((error) => {
console.error(error)
})
res.redirect('success')
})
app.get('/success', (req, res) => {
res.render('success')
})
app.get('/videos', (req, res) => {
res.render('videos')
})
app.get('/about-us', (req, res) => {
res.render('about-us')
})
app.use(function (req, res, next) {
res.status(404).render('404')
})
// Starting to listen from the PORT
app.listen(PORT, () => {
console.log('Online!!')
})