This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
send-reset-pwd.js
executable file
·57 lines (45 loc) · 1.77 KB
/
send-reset-pwd.js
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
const makeDebug = require('debug');
const concatIDAndHash = require('./helpers/concat-id-and-hash');
const ensureObjPropsValid = require('./helpers/ensure-obj-props-valid');
const getUserData = require('./helpers/get-user-data');
const { getLongToken, getShortToken } = require('@feathers-plus/commons');
const debug = makeDebug('authLocalMgnt:sendResetPwd');
module.exports = sendResetPwd;
async function sendResetPwd (
{ options, plugins }, identifyUser, notifierOptions, authUser, provider
) {
debug('sendResetPwd');
const usersService = options.app.service(options.service);
const usersServiceIdName = usersService.id;
debug('id', usersService.id);
ensureObjPropsValid(identifyUser, options.identifyUserProps);
const users = await plugins.run('sendResetPwd.find', {
usersService,
params: { query: identifyUser },
});
const user1 = getUserData(users, options.skipIsVerifiedCheck ? [] : ['isVerified']);
const user2 = Object.assign(user1, {
resetExpires: Date.now() + options.resetDelay,
resetToken: concatIDAndHash(
user1[usersServiceIdName],
await getLongToken(options.longTokenLen)
),
resetShortToken: await getShortToken(options.shortTokenLen, options.shortTokenDigits),
});
const user3 = await plugins.run('sanitizeUserForNotifier', user2);
await plugins.run('notifier', {
type: 'sendResetPwd',
sanitizedUser: user3,
notifierOptions,
});
const user4 = await plugins.run('sendResetPwd.patch', {
usersService,
id: user1[usersServiceIdName],
data: {
resetExpires: user2.resetExpires,
resetToken: user2.resetToken,
resetShortToken: user2.resetShortToken,
},
});
return await plugins.run('sanitizeUserForClient', user4);
}