verifyEmail.js
3.42 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
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: white;
height: 50px;
}
.brand-style
{
font-family: 'Ubuntu', sans-serif !important;
color:#00b395;
}
.congo-wrap .header .container {
width: 100%;
}
.congo-wrap{
background:#00b395;
height:100%;
}
.widgetbox-congrats {
margin: 20px auto;
width: 400px;
height: auto;
padding: 20px;
-webkit-border-radius: 8px/7px;
-moz-border-radius: 8px/7px;
border-radius: 8px/7px;
background-color: white;
-webkit-box-shadow: 1px 2px 5px rgba(0,0,0,.31);
-moz-box-shadow: 1px 2px 5px rgba(0,0,0,.31);
box-shadow: 1px 2px 5px rgba(0,0,0,.31);
border: solid 1px #cbc9c9;
font-family: 'Ubuntu', sans-serif;
}
body {
margin: 0;
padding: 0;
}
.text-blue {
color: #00b395;
}
.widgetbox-congrats .congo-msg h4 {
margin: 8px 0;
font-size: 24px;
text-align:center;
}
.widgetbox-congrats .congo-msg .icon {
color: #00b395;
font-size: 90px;
display: inline-block;
width: 100%;
text-align: center;
}
p
{
display: inline-block;
width: 100%;
text-align: center;
}
.widgetbox-congrats .widgetbox-footer .btn {
background: #00b395;
color: #fff;
text-transform: uppercase;
display: inline-block;
width: 100%;
text-align: center;
font-family: 'Ubuntu', sans-serif;s
}
</style>
</head>
<body>
<div class="congo-wrap">
<div class="header">
<div class="container">
<span class="brand-style">YOUNGDESK</span>
</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-md 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,
}});
});