verifyEmail.js
3.85 KB
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
import React from 'react';
import _ from 'lodash';
import { Users } from '/imports/collections/users/index';
const finishWithMessage = (res, message, redirect = "/") => {
const output = `
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style type="text/css">
.congo-wrap .header {
background: #379AC7;
background: -webkit-linear-gradient(-90deg, #379AC7, #0460D9);
background: linear-gradient(180deg, #379AC7, #0460D9);
height: 80px;
padding: 11px 0;
}
.logo img{
width:170px;
}
.congo-wrap .header .container {
width: 100%;
padding:0 20px;
}
.congo-wrap{
background:#f6f7f7;
height:100%;
}
.widgetbox-congrats {
max-width: 720px;
margin: 0px auto;
background: #fff;
position: relative;
top: 20px;
text-align: center;
border: 1px solid #eee;
font-size: 20px;
}
body {
margin: 0;
padding: 0;
}
.widgetbox-congrats .congo-msg {
padding: 90px 0;
border-bottom: 1px solid #eee;
}
.widgetbox-congrats.congo-msg h4 {margin: 0 !important;padding: 0 !important;}
.text-blue {
color: #0059ce;
}
.widgetbox-congrats .congo-msg h4 {
margin: 8px 0;
font-size: 24px;
}
.widgetbox-congrats .congo-msg .icon {
color: #0F67C8;
font-size: 90px;
font-weight: 100;
margin-bottom: 20px;
display: block;
}
.widgetbox-congrats .widgetbox-footer {
padding: 31px 10px;
}
.widgetbox-congrats .widgetbox-footer .btn {
background: #0e89d3;
color: #fff;
padding: 10px 30px;
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="congo-wrap">
<div class="header">
<div class="container">
<div class="logo">
<img src="/files/images/svg/logo--white.svg" altt=""/>
</div>
</div>
</div>
<div class="container">
<div class="widgetbox-congrats">
<div class="congo-msg">
<div class="text-blue">
<i class="icon icon-simple icon-check"></i>
<h4>Congrats!</h4>
</div>
<p> ${message}</p>
</div>
<div class="widgetbox-footer">
<a href="${redirect}" class="btn btn-lg btn-prmary">Continue</a>
</div>
</div>
</div>
</div>
</html>
`;
res.writeHead(200, {
'Content-Length': output.length,
'Content-Type': 'text/html',
});
res.end(output);
};
Picker.route('/back/verifyEmail/:token', function(params, req, res, next) {
const user = Users.findOne({'services.email.verificationTokens.token': params.token});
if(!user) return finishWithMessage(res, 'Invalid or outdated token.');
const token = _.find(user.services.email.verificationTokens, x => x.token === params.token);
if(new Date().getTime() - token.when.getTime() > 2 * 24 * 60 * 60 * 1000) return finishWithMessage(res, 'Invalid or outdated token.');
finishWithMessage(res, 'Email has been verified.',"/");
const idx = _.findIndex(user.emails, x => x.address === token.address);
Users.update({_id: user._id}, {$set: {
[`emails.${idx}.verified`]: true,
}});
// "services": {
// "password": {
// "bcrypt": "$2a$10$FqOvMve/MonERrLIOCJbruvS9iHoz5ixknGfm/ZAiOt9EiF43W4Z6"
// },
// "email": {
// "verificationTokens": [
// {
// "token": "05T-Ht_BzprDSAOVIYC-yUvDQ3Hp0wNym4eTx2g1VmI",
// "address": "krowa@druga.je",
// "when": new Date(1479502106631)
// }
// ]
// },
});