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 | /* global module: 0 */ // Wrapper for client interface to feathers-service-verify-reset function VerifyReset (app) { // eslint-disable-line no-unused-vars if (!(this instanceof VerifyReset)) { return new VerifyReset(app); } const verifyReset = app.service('verifyReset'); this.checkUnique = (uniques, ownId, ifErrMsg, cb) => verifyReset.create({ action: 'checkUnique', value: uniques, ownId, meta: { noErrMsg: ifErrMsg } }, {}, cb); this.resendVerifySignup = (emailOrToken, notifierOptions, cb) => verifyReset.create({ action: 'resendVerifySignup', value: emailOrToken, notifierOptions }, {}, cb); this.verifySignupLong = (token, cb) => verifyReset.create({ action: 'verifySignupLong', value: token }, {}, cb); this.verifySignupShort = (token, userFind, cb) => verifyReset.create({ action: 'verifySignupShort', value: { token, user: userFind } }, {}, cb); this.sendResetPwd = (email, notifierOptions, cb) => verifyReset.create({ action: 'sendResetPwd', value: email, notifierOptions }, {}, cb); this.resetPwdLong = (token, password, cb) => verifyReset.create({ action: 'resetPwdLong', value: { token, password } }, {}, cb); this.resetPwdShort = (token, userFind, password, cb) => verifyReset.create({ action: 'resetPwdShort', value: { token, password, user: userFind } }, {}, cb); this.passwordChange = (oldPassword, password, user, cb) => verifyReset.create({ action: 'passwordChange', value: { oldPassword, password } }, { user }, cb); this.emailChange = (password, email, user, cb) => verifyReset.create({ action: 'emailChange', value: { password, email } }, { user }, cb); this.authenticate = (email, password, cb) => { let cbCalled = false; return app.authenticate({ type: 'local', email, password }) .then(result => { const user = result.data; if (!user || !user.isVerified) { app.logout(); return cb(new Error(user ? 'User\'s email is not verified.' : 'No user returned.')); } if (cb) { cbCalled = true; return cb(null, user); } return user; }) .catch((err) => { if (!cbCalled) { cb(err); } }); }; // backwards compatability this.unique = this.checkUnique; this.resend = this.resendVerifySignup; this.verifySignUp = this.verifySignupLong; this.sendResetPassword = this.sendResetPwd; this.saveResetPassword = this.resetPwdLong; this.changePassword = this.passwordChange; this.changeEmail = this.emailChange; } if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { module.exports = VerifyReset; } |