Conditions | 9 |
Paths | 20 |
Total Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import fs from 'fs-extra' |
||
41 | User.utils.findByResetPasswordToken(req.body.token, function (err, userToReset) { |
||
42 | var msg = '' |
||
43 | if (err) { |
||
44 | msg = 'Error' |
||
45 | }else if (typeof userToReset === 'undefined' || userToReset === null) { |
||
46 | msg = 'Invalid token' |
||
47 | }else { |
||
48 | var d = new Date().getTime() |
||
49 | d = (((d - userToReset.resetPasswordExpires) / 1000) / 60) |
||
50 | if (d > 0) { |
||
51 | msg = 'Token expired' |
||
52 | } |
||
53 | } |
||
54 | if (msg !== '') { |
||
55 | |||
56 | page = path.join(__dirname + '/../../../views/users/reset.html') |
||
57 | if (coreUtils.file.exist(page)) { |
||
58 | resHtml = fs.readFileSync(page, 'utf8') |
||
59 | } |
||
60 | |||
61 | template = Handlebars.compile(resHtml, {noEscape: true}) |
||
62 | |||
63 | tmp = template({ |
||
64 | csrfToken: res.locals.csrfToken, |
||
65 | config: JSON.stringify(config), |
||
66 | express: { |
||
67 | req: req, |
||
68 | res: res |
||
69 | }, |
||
70 | token: req.body.token, |
||
71 | info: msg |
||
72 | }) |
||
73 | |||
74 | return res.send(tmp) |
||
75 | } |
||
76 | |||
77 | userToReset.password = req.body.password |
||
78 | var resUpdatePassword = User.operations.updatePassword(userToReset, req.body.password) |
||
79 | if (resUpdatePassword.success === 1) { |
||
80 | var login = config.users.login |
||
81 | res.redirect(login) |
||
82 | }else { |
||
83 | page = path.join(__dirname + '/../../../views/users/reset.html') |
||
84 | if (coreUtils.file.exist(page)) { |
||
85 | resHtml = fs.readFileSync(page, 'utf8') |
||
86 | } |
||
87 | |||
88 | template = Handlebars.compile(resHtml, {noEscape: true}) |
||
89 | |||
90 | tmp = template({ |
||
91 | csrfToken: res.locals.csrfToken, |
||
92 | config: JSON.stringify(config), |
||
93 | express: { |
||
94 | req: req, |
||
95 | res: res |
||
96 | }, |
||
97 | token: req.body.token, |
||
98 | info: resUpdatePassword.message |
||
99 | }) |
||
100 | |||
101 | return res.send(tmp) |
||
102 | } |
||
103 | }) |
||
104 | }else if(typeof req.body.token !== 'undefined' && req.body.token !== null) { |
||
111 | export default route |