mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
refactor: change password/user follow to use api lib
This commit is contained in:
@@ -5,6 +5,8 @@ const groups = require('../groups');
|
||||
const meta = require('../meta');
|
||||
const flags = require('../flags');
|
||||
const privileges = require('../privileges');
|
||||
const notifications = require('../notifications');
|
||||
const plugins = require('../plugins');
|
||||
const events = require('../events');
|
||||
|
||||
const usersAPI = module.exports;
|
||||
@@ -74,6 +76,47 @@ usersAPI.deleteMany = async function (caller, data) {
|
||||
}
|
||||
};
|
||||
|
||||
usersAPI.changePassword = async function (caller, data) {
|
||||
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
||||
await events.log({
|
||||
type: 'password-change',
|
||||
uid: caller.uid,
|
||||
targetUid: data.uid,
|
||||
ip: caller.ip,
|
||||
});
|
||||
};
|
||||
|
||||
usersAPI.follow = async function (caller, data) {
|
||||
await user.follow(caller.uid, data.uid);
|
||||
plugins.fireHook('action:user.follow', {
|
||||
fromUid: caller.uid,
|
||||
toUid: data.uid,
|
||||
});
|
||||
|
||||
const userData = await user.getUserFields(caller.uid, ['username', 'userslug']);
|
||||
const notifObj = await notifications.create({
|
||||
type: 'follow',
|
||||
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
|
||||
nid: 'follow:' + data.uid + ':uid:' + caller.uid,
|
||||
from: caller.uid,
|
||||
path: '/uid/' + data.uid + '/followers',
|
||||
mergeId: 'notifications:user_started_following_you',
|
||||
});
|
||||
if (!notifObj) {
|
||||
return;
|
||||
}
|
||||
notifObj.user = userData;
|
||||
await notifications.push(notifObj, [data.uid]);
|
||||
};
|
||||
|
||||
usersAPI.unfollow = async function (caller, data) {
|
||||
await user.unfollow(caller.uid, data.uid);
|
||||
plugins.fireHook('action:user.unfollow', {
|
||||
fromUid: caller.uid,
|
||||
toUid: data.uid,
|
||||
});
|
||||
};
|
||||
|
||||
async function processDeletion(uid, caller) {
|
||||
const isTargetAdmin = await user.isAdministrator(uid);
|
||||
const isSelf = parseInt(uid, 10) === caller.uid;
|
||||
|
||||
Reference in New Issue
Block a user