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 | 1x 1x 1x 1x 1x 1x 1x 1x 120x 350x 350x 350x 350x 350x 350x 350x 350x 329x 329x 44x 76x 28x 44x 28x 24x 40x 16x 16x 13x | /* eslint-env node */ const errors = require('feathers-errors'); const debug = require('debug')('authManagement:main'); const checkUniqueness = require('./checkUniqueness'); const resendVerifySignup = require('./resendVerifySignup'); const { verifySignupWithLongToken, verifySignupWithShortToken } = require('./verifySignup'); const sendResetPwd = require('./sendResetPwd'); const { resetPwdWithLongToken, resetPwdWithShortToken } = require('./resetPassword'); const passwordChange = require('./passwordChange'); const identityChange = require('./identityChange'); const optionsDefault = { app: null, service: '/users', // need exactly this for test suite path: 'authManagement', notifier: () => Promise.resolve(), longTokenLen: 15, // token's length will be twice this shortTokenLen: 6, shortTokenDigits: true, resetDelay: 1000 * 60 * 60 * 2, // 2 hours delay: 1000 * 60 * 60 * 24 * 5, // 5 days identifyUserProps: ['email'] }; module.exports = function (options1 = {}) { debug('service being configured.'); const options = Object.assign({}, optionsDefault, options1); return function () { return authManagement(options, this); }; }; function authManagement (options, app) { // 'function' needed as we use 'this' debug('service initialized'); options.app = app; options.app.use(options.path, { create (data) { debug(`service called. action=${data.action}`); switch (data.action) { case 'checkUnique': return checkUniqueness(options, data.value, data.ownId || null, data.meta || {}); case 'resendVerifySignup': return resendVerifySignup(options, data.value, data.notifierOptions); case 'verifySignupLong': return verifySignupWithLongToken(options, data.value); case 'verifySignupShort': return verifySignupWithShortToken(options, data.value.token, data.value.user); case 'sendResetPwd': return sendResetPwd(options, data.value, data.notifierOptions); case 'resetPwdLong': return resetPwdWithLongToken(options, data.value.token, data.value.password); case 'resetPwdShort': return resetPwdWithShortToken( options, data.value.token, data.value.user, data.value.password); case 'passwordChange': return passwordChange( options, data.value.user, data.value.oldPassword, data.value.password); case 'identityChange': return identityChange( options, data.value.user, data.value.password, data.value.changes); case 'options': return Promise.resolve(options); default: return Promise.reject(new errors.BadRequest(`Action '${data.action}' is invalid.`, { errors: { $className: 'badParams' } })); } } }); } |