Cockatrice/webclient/src/websocket/commands/session/forgotPasswordReset.ts
2026-04-12 15:55:00 -05:00

38 lines
1.2 KiB
TypeScript

import { ForgotPasswordResetParams } from 'store';
import { StatusEnum, WebSocketConnectOptions } from 'types';
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { SessionPersistence } from '../../persistence';
import { hashPassword } from '../../utils';
import { disconnect, updateStatus } from '.';
export function forgotPasswordReset(options: WebSocketConnectOptions, newPassword?: string, passwordSalt?: string): void {
const { userName, token } = options as unknown as ForgotPasswordResetParams;
const params: any = {
...webClient.clientConfig,
userName,
token,
};
if (passwordSalt) {
params.hashedNewPassword = hashPassword(passwordSalt, newPassword);
} else {
params.newPassword = newPassword;
}
BackendService.sendSessionCommand('Command_ForgotPasswordReset', params, {
onSuccess: () => {
updateStatus(StatusEnum.DISCONNECTED, null);
SessionPersistence.resetPasswordSuccess();
disconnect();
},
onError: () => {
updateStatus(StatusEnum.DISCONNECTED, null);
SessionPersistence.resetPasswordFailed();
disconnect();
},
});
}