'use strict';
import { apiBadRequestResponse, apiNotFoundResponse, apiOkResponse } from '../../../meta/server/web/responses.js';
import { passwordMessages } from '../../../../fd-toolbox-core/constants/password-messages.js';
import { resetPassword } from '../../users/user-manager.js';
import { parseJsonBodyFromRequest } from '../../../../fd-toolbox/lib/utils.js';
import { getUserByEmail } from '../../users/user-db.js';

var __defProp=Object['defineProperty'],__name=(_0x55512a,_0x14bc61)=>__defProp(_0x55512a,'name',{'value':_0x14bc61,'configurable':!![]});async function resetpasswordPostRoute(_0x47881f){const _0x222775=await parseJsonBodyFromRequest(_0x47881f);let _0x1498cb;if(!_0x222775['password'])_0x1498cb=apiBadRequestResponse(passwordMessages['passwordRequired']);else {if(!_0x222775['token'])_0x1498cb=apiBadRequestResponse(passwordMessages['tokenRequired']);else {if(!_0x222775['email'])_0x1498cb=apiBadRequestResponse(passwordMessages['emailRequired']);else {if(_0x222775['password']!==_0x222775['confirmPassword'])_0x1498cb=apiBadRequestResponse(passwordMessages['passwordsDontMatch']);else {const _0x190b92=await getUserByEmail(_0x222775['email']);if(!_0x190b92)_0x1498cb=apiNotFoundResponse(void(-0x13d+0x6f1+-0x5b4));else {const _0x4b9b09=await resetPassword(_0x222775['token'],_0x190b92,_0x222775['password']);_0x1498cb=_0x4b9b09['isSuccess']?apiOkResponse(_0x4b9b09['userFriendlyMessage']):apiBadRequestResponse(_0x4b9b09['userFriendlyMessage']);}}}}}return _0x1498cb;}__name(resetpasswordPostRoute,'resetpasswordPostRoute');

export { resetpasswordPostRoute };
