· 9 years ago · Dec 04, 2016, 08:18 AM
1// global variable
2var resetQueryParameters = '';
3
4//CAPTURE TOKEN (QUERY PARAMS) FROM LINK
5app.get('/resetQuery/', function (req, res) {
6
7 //SET THE TOKEN TO VARIABLE
8 resetQueryParameters = req.query.token;
9 r.db('myDB').table('Reset_Password').filter(r.row('auth_key').eq(req.query.token)).
10 run(myConnection, function (err, cursor) {
11 if (err) {
12 return next(err);
13 }
14 cursor.toArray(function (err, result) {
15 if (err) {
16 throw err;
17 } else {
18 if (result.length > 0) {
19 res.redirect(redirectResetPage);
20 } else {
21 res.redirect(redirectLoginPage);
22 }
23 return result;
24 console.log("printing reset link from db.....", JSON.stringify(result, null, 2));
25 }
26 });
27 });
28});
29
30function resetPassword(req, res, next) {
31 console.log('reset password called from external link.....');
32
33 nJwt.verify(resetQueryParameters, secretKey, function (err, verifiedJwt) {
34 if (err) {
35 console.log('reset token not valid...', err);
36 } else {
37 var params = {
38 'username': verifiedJwt.body.details,
39 'newPassword': req.params.newPassword
40 };
41
42 getApiResponse(resetURL, params, function (res1) {
43 console.log('sending reset params to server...', params);
44 if (res1.error) {
45 console.log('Could not reset password......', res1.error);
46 } else {
47 console.log('reset password success.....');
48 resetQueryParameters = '';
49 res.json(res1);
50 }
51 });
52 }
53 });
54}