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 | 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x | /* global module: 0 */ // Wrapper for client interface to feathers-authenticate-management function AuthManagement (app) { // eslint-disable-line no-unused-vars Iif (!(this instanceof AuthManagement)) { return new AuthManagement(app); } const authManagement = app.service('authManagement'); this.checkUnique = (identifyUser, ownId, ifErrMsg, cb) => authManagement.create({ action: 'checkUnique', value: identifyUser, ownId, meta: { noErrMsg: ifErrMsg } }, {}, cb); this.resendVerifySignup = (identifyUser, notifierOptions, cb) => authManagement.create({ action: 'resendVerifySignup', value: identifyUser, notifierOptions }, {}, cb); this.verifySignupLong = (verifyToken, cb) => authManagement.create({ action: 'verifySignupLong', value: verifyToken }, {}, cb); this.verifySignupShort = (verifyShortToken, identifyUser, cb) => authManagement.create({ action: 'verifySignupShort', value: { user: identifyUser, token: verifyShortToken } }, {}, cb); this.sendResetPwd = (identifyUser, notifierOptions, cb) => authManagement.create({ action: 'sendResetPwd', value: identifyUser, notifierOptions }, {}, cb); this.resetPwdLong = (resetToken, password, cb) => authManagement.create({ action: 'resetPwdLong', value: { token: resetToken, password } }, {}, cb); this.resetPwdShort = (resetShortToken, identifyUser, password, cb) => authManagement.create({ action: 'resetPwdShort', value: { user: identifyUser, token: resetShortToken, password } }, {}, cb); this.passwordChange = (oldPassword, password, identifyUser, cb) => authManagement.create({ action: 'passwordChange', value: { user: identifyUser, oldPassword, password } }, {}, cb); this.identityChange = (password, changesIdentifyUser, identifyUser, cb) => authManagement.create({ action: 'identityChange', value: { user: identifyUser, password, changes: changesIdentifyUser } }, {}, 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.')); } Iif (cb) { cbCalled = true; return cb(null, user); } return user; }) .catch((err) => { Eif (!cbCalled) { cb(err); } }); }; } Eif (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { module.exports = AuthManagement; } |