reset account + password required in api

This commit is contained in:
negue
2023-02-05 18:52:54 +01:00
parent 64f7e7a1d9
commit bec75c6e12
3 changed files with 57 additions and 9 deletions
+16 -1
View File
@@ -3,6 +3,8 @@ import * as userLib from '../../libs/user';
import { verifyDisplayName } from '../../libs/user/validation';
import common from '../../../common';
import { TransactionModel as Transaction } from '../../models/transaction';
import { BadRequest, NotAuthorized } from '../../libs/errors';
import * as passwordUtils from '../../libs/password';
const api = {};
@@ -60,7 +62,7 @@ const api = {};
* }
* }
*
*/
*/
api.getUser = {
method: 'GET',
middlewares: [authWithHeaders()],
@@ -193,6 +195,8 @@ api.userReroll = {
* @apiName UserReset
* @apiGroup User
*
* @apiParam (Body) {String} password The user's password
*
* @apiSuccess {Object} data.user
* @apiSuccess {Array} data.tasksToRemove IDs of removed tasks
* @apiSuccess {String} message Success message
@@ -214,6 +218,17 @@ api.userReset = {
middlewares: [authWithHeaders()],
url: '/user/reset',
async handler (req, res) {
const { user } = res.locals;
const { password } = req.body;
if (!password) {
throw new BadRequest(res.t('missingPassword'));
}
const isValidPassword = await passwordUtils.compare(user, password);
if (!isValidPassword) {
throw new NotAuthorized(res.t('wrongPassword'));
}
await userLib.reset(req, res, { isV3: false });
},
};