-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpageController.js
223 lines (180 loc) · 5.84 KB
/
pageController.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import nodemailer from 'nodemailer';
import Photo from '../models/photoModels.js'
import User from '../models/userModel.js'
//sort siralamada kullaniriy son yukenne onde dyruru
//numOfUser kullanici sayisi
const getIndexPage = async(req,res)=>{
const photos = await Photo.find().sort({uploadeAt:-1}).limit(3)
const numOfUser = await User.countDocuments({})
const numOfPhotos = await Photo.countDocuments({})
res.render('index',{
link:'index',
photos,
numOfUser,
numOfPhotos
})
}
//sayafalara felindigindeki aktiv oaln sayfayi gosyermek icin link yaptim
const getAboutPage =(req,res)=>{
res.render('about',{
link:'about'
})
}
const getRegisterPage =(req,res)=>{
res.render('register',{
link:'register'
})
}
const getLoginPage =(req,res)=>{
res.render('login',{
link:'login'
})
}
//burda bir saniye vereek token ucmasini saglariy
const getLogout =(req,res)=>{
res.cookie('jwt','',{
maxAge:1
})
res.redirect('/')
}
const getContactPage =(req,res)=>{
res.render('contact',{
link:'contact'
})
}
const sendMail= async(req,res)=>{
const htmlTemplate=`
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Simple Transactional Email</title>
<style>
/* -------------------------------------
GLOBAL RESETS
------------------------------------- */
/*All the styling goes here*/
img {
border: none;
-ms-interpolation-mode: bicubic;
max-width: 100%;
}
body {
background-color: #f6f6f6;
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 14px;
line-height: 1.4;
margin: 0;
padding: 0;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
table {
border-collapse: separate;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
width: 100%; }
table td {
font-family: sans-serif;
font-size: 14px;
vertical-align: top;
}
/* -------------------------------------
BODY & CONTAINER
------------------------------------- */
.body {
background-color: #f6f6f6;
width: 100%;
}
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display: block;
margin: 0 auto !important;
/* makes it centered */
max-width: 580px;
padding: 10px;
width: 580px;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
box-sizing: border-box;
display: block;
margin: 0 auto;
max-width: 580px;
padding: 10px;
}
/* -------------------------------------
HEADER, FOOTER, MAIN
------------------------------------- */
.main {
background: #ffffff;
border-radius: 3px;
width: 100%;
}
.wrapper {
box-sizing: border-box;
padding: 20px;
}
.content-block {
padding-bottom: 10px;
padding-top: 10px;
}
</style>
</head>
<body>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td> </td>
<td class="container">
<div class="content">
<!-- START CENTERED WHITE CONTAINER -->
<table role="presentation" class="main">
<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper">
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>Email: ${req.body.email}</p>
<p>Name: ${req.body.name}</p>
<p>Message: ${req.body.message}</p>
</td>
</tr>
</table>
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
<td> </td>
</tr>
</table>
</body>
</html>
`;
try {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: process.env.NODE_MAIL, // generated ethereal user
pass: process.env.NODE_PASS, // generated ethereal password
},
});
// send mail with defined transport object
await transporter.sendMail({
to: '[email protected]', // list of receivers
subject: `MAIL FROM ${req.body.email}`, // Subject line
html: htmlTemplate, // html body
});
res.status(200).json({ succeeded: true });
} catch (err) {
}
}
export {getIndexPage,getAboutPage,getRegisterPage,getLoginPage ,getLogout,getContactPage,sendMail}