mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
Add few more interfaces (#5063)
This commit is contained in:
parent
e261e16d99
commit
8687163cca
34 changed files with 359 additions and 90 deletions
19
webclient/src/websocket/commands/session/deckDel.ts
Normal file
19
webclient/src/websocket/commands/session/deckDel.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckDel(deckId: number): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckDel.create({ deckId });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDel.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckDelete(deckId);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
});
|
||||
}
|
||||
19
webclient/src/websocket/commands/session/deckDelDir.ts
Normal file
19
webclient/src/websocket/commands/session/deckDelDir.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckDelDir(path: string): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckDelDir.create({ path });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDelDir.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckDeleteDir(path);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
});
|
||||
}
|
||||
19
webclient/src/websocket/commands/session/deckDownload.ts
Normal file
19
webclient/src/websocket/commands/session/deckDownload.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckDownload(deckId: number): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckDownload.create({ deckId });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDownload.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckDownload(deckId);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
});
|
||||
}
|
||||
22
webclient/src/websocket/commands/session/deckList.ts
Normal file
22
webclient/src/websocket/commands/session/deckList.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckList(): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckList.create();
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckList.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
const response = raw['.Response_DeckList.ext'];
|
||||
|
||||
if (response) {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckList(response);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
19
webclient/src/websocket/commands/session/deckNewDir.ts
Normal file
19
webclient/src/websocket/commands/session/deckNewDir.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckNewDir(path: string, dirName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckNewDir.create({ path, dirName });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckNewDir.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckNewDir(path, dirName);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
});
|
||||
}
|
||||
23
webclient/src/websocket/commands/session/deckUpload.ts
Normal file
23
webclient/src/websocket/commands/session/deckUpload.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function deckUpload(path: string, deckId: number, deckList: string): void {
|
||||
const command = webClient.protobuf.controller.Command_DeckUpload.create({ path, deckId, deckList });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckUpload.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
const response = raw['.Response_DeckUpload.ext'];
|
||||
|
||||
if (response) {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.deckUpload(response);
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to do the thing');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
|
@ -1,34 +1,33 @@
|
|||
import { ForgotPasswordResetParams } from 'store';
|
||||
import { ForgotPasswordParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { hashPassword } from '../../utils';
|
||||
|
||||
import { disconnect, updateStatus } from '.';
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordRequest(options: WebSocketConnectOptions, passwordSalt?: string): void {
|
||||
const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams;
|
||||
export function forgotPasswordRequest(options: WebSocketConnectOptions): void {
|
||||
const { userName } = options as unknown as ForgotPasswordParams;
|
||||
|
||||
const forgotPasswordResetConfig: any = {
|
||||
const forgotPasswordConfig = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
token,
|
||||
};
|
||||
|
||||
if (passwordSalt) {
|
||||
forgotPasswordResetConfig.hashedNewPassword = hashPassword(passwordSalt, newPassword);
|
||||
} else {
|
||||
forgotPasswordResetConfig.newPassword = newPassword;
|
||||
}
|
||||
|
||||
const command = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordReset.ext': command });
|
||||
const command = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordRequest.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordSuccess();
|
||||
const resp = raw['.Response_ForgotPasswordRequest.ext'];
|
||||
|
||||
if (resp.challengeEmail) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
}
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import { ForgotPasswordResetParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { hashPassword } from '../../utils';
|
||||
|
||||
import { disconnect, updateStatus } from '.';
|
||||
|
||||
export function forgotPasswordReset(options: WebSocketConnectOptions, passwordSalt?: string): void {
|
||||
const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams;
|
||||
|
||||
const forgotPasswordResetConfig: any = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
token,
|
||||
};
|
||||
|
||||
if (passwordSalt) {
|
||||
forgotPasswordResetConfig.hashedNewPassword = hashPassword(passwordSalt, newPassword);
|
||||
} else {
|
||||
forgotPasswordResetConfig.newPassword = newPassword;
|
||||
}
|
||||
|
||||
const command = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordReset.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordSuccess();
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
});
|
||||
}
|
||||
|
|
@ -1,22 +1,35 @@
|
|||
export * from './accountEdit';
|
||||
export * from './accountImage';
|
||||
export * from './accountPassword';
|
||||
export * from './activate';
|
||||
export * from './addToList';
|
||||
export * from './connect';
|
||||
export * from './deckDel';
|
||||
export * from './deckDelDir';
|
||||
export * from './deckDownload';
|
||||
export * from './deckList';
|
||||
export * from './deckNewDir';
|
||||
export * from './deckUpload';
|
||||
export * from './disconnect';
|
||||
export * from './forgotPasswordChallenge'
|
||||
export * from './forgotPasswordRequest';
|
||||
export * from './forgotPasswordReset';
|
||||
export * from './getGamesOfUser';
|
||||
export * from './getUserInfo';
|
||||
export * from './joinRoom';
|
||||
export * from './listRooms';
|
||||
export * from './listUsers';
|
||||
export * from './login';
|
||||
export * from './message';
|
||||
export * from './ping';
|
||||
export * from './register';
|
||||
export * from './removeFromList';
|
||||
export * from './requestPasswordSalt';
|
||||
export * from './forgotPasswordRequest';
|
||||
export * from './forgotPasswordChallenge'
|
||||
export * from './resetPasswordRequest';
|
||||
export * from './updateStatus';
|
||||
export * from './accountPassword';
|
||||
export * from './accountEdit';
|
||||
export * from './accountImage';
|
||||
export * from './message';
|
||||
export * from './getUserInfo';
|
||||
export * from './getGamesOfUser';
|
||||
export * from './ping';
|
||||
|
||||
/** TODO
|
||||
* REPLAY_DELETE_MATCH
|
||||
* REPLAY_DOWNLOAD
|
||||
* REPLAY_LIST
|
||||
* REPLAY_MODIFY_MATCH
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
activate,
|
||||
disconnect,
|
||||
login,
|
||||
forgotPasswordRequest,
|
||||
forgotPasswordReset,
|
||||
updateStatus
|
||||
} from './';
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ export function requestPasswordSalt(options: WebSocketConnectOptions): void {
|
|||
}
|
||||
|
||||
case WebSocketConnectReason.PASSWORD_RESET: {
|
||||
forgotPasswordRequest(options, passwordSalt);
|
||||
forgotPasswordReset(options, passwordSalt);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
import { ForgotPasswordParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function resetPasswordRequest(options: WebSocketConnectOptions): void {
|
||||
const { userName } = options as unknown as ForgotPasswordParams;
|
||||
|
||||
const forgotPasswordConfig = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
};
|
||||
|
||||
const command = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordRequest.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
const resp = raw['.Response_ForgotPasswordRequest.ext'];
|
||||
|
||||
if (resp.challengeEmail) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
}
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue