mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Initial implementation completion and refactor
This commit is contained in:
parent
e977f123ce
commit
f0bf865646
76 changed files with 897 additions and 890 deletions
|
|
@ -1,25 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function accountEdit(passwordCheck: string, realName?: string, email?: string, country?: string): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountEdit.create({ passwordCheck, realName, email, country });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountEdit.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountEditChanged(realName, email, country);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_AccountEdit', { passwordCheck, realName, email, country }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountEditChanged(realName, email, country);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { common } from 'protobufjs';
|
||||
import IBytesValue = common.IBytesValue;
|
||||
|
||||
export function accountImage(image: IBytesValue): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountImage.create({ image });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountImage.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountImageChanged(image);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
export function accountImage(image: Uint8Array): void {
|
||||
BackendService.sendSessionCommand('Command_AccountImage', { image }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountImageChanged(image);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function accountPassword(oldPassword: string, newPassword: string, hashedNewPassword: string): void {
|
||||
const command = webClient.protobuf.controller.Command_AccountPassword.create({ oldPassword, newPassword, hashedNewPassword });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountPassword.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.accountPasswordChange();
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to change password');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_AccountPassword', { oldPassword, newPassword, hashedNewPassword }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountPasswordChange();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { AccountActivationParams } from 'store';
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { ProtoController } from '../../services/ProtoController';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
import { disconnect, login, updateStatus } from './';
|
||||
|
|
@ -9,23 +11,21 @@ import { disconnect, login, updateStatus } from './';
|
|||
export function activate(options: WebSocketConnectOptions, passwordSalt?: string): void {
|
||||
const { userName, token } = options as unknown as AccountActivationParams;
|
||||
|
||||
const accountActivationConfig = {
|
||||
BackendService.sendSessionCommand('Command_Activate', {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
token,
|
||||
};
|
||||
|
||||
const command = webClient.protobuf.controller.Command_Activate.create(accountActivationConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Activate.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
|
||||
SessionPersistence.accountActivationSuccess();
|
||||
login(options, passwordSalt);
|
||||
} else {
|
||||
}, {
|
||||
onResponseCode: {
|
||||
[ProtoController.root.Response.ResponseCode.RespActivationAccepted]: () => {
|
||||
SessionPersistence.accountActivationSuccess();
|
||||
login(options, passwordSalt);
|
||||
},
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
|
||||
disconnect();
|
||||
SessionPersistence.accountActivationFailed();
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function addToBuddyList(userName: string): void {
|
||||
|
|
@ -10,16 +10,9 @@ export function addToIgnoreList(userName: string): void {
|
|||
}
|
||||
|
||||
export function addToList(list: string, userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_AddToList.create({ list, userName });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AddToList.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.addToList(list, userName);
|
||||
break;
|
||||
default:
|
||||
console.error('Failed to add to list', responseCode);
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_AddToList', { list, userName }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.addToList(list, userName);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_DeckDel', { deckId }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.deleteServerDeck(deckId);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_DeckDelDir', { path }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.deleteServerDeckDir(path);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,22 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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');
|
||||
}
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_DeckList', {}, {
|
||||
responseName: 'Response_DeckList',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.updateServerDecks(response);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_DeckNewDir', { path, dirName }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.createServerDeckDir(path, dirName);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
BackendService.sendSessionCommand('Command_DeckUpload', { path, deckId, deckList }, {
|
||||
responseName: 'Response_DeckUpload',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.uploadServerDeck(path, response.newFile);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,30 +2,27 @@ import { ForgotPasswordChallengeParams } from 'store';
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordChallenge(options: WebSocketConnectOptions): void {
|
||||
const { userName, email } = options as unknown as ForgotPasswordChallengeParams;
|
||||
|
||||
const forgotPasswordChallengeConfig = {
|
||||
BackendService.sendSessionCommand('Command_ForgotPasswordChallenge', {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
email,
|
||||
};
|
||||
|
||||
const command = webClient.protobuf.controller.Command_ForgotPasswordChallenge.create(forgotPasswordChallengeConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordChallenge.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
} else {
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
disconnect();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { ForgotPasswordParams } from 'store';
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
|
@ -9,30 +10,25 @@ import { disconnect, updateStatus } from './';
|
|||
export function forgotPasswordRequest(options: WebSocketConnectOptions): void {
|
||||
const { userName } = options as unknown as ForgotPasswordParams;
|
||||
|
||||
const forgotPasswordConfig = {
|
||||
BackendService.sendSessionCommand('Command_ForgotPasswordRequest', {
|
||||
...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) {
|
||||
}, {
|
||||
responseName: 'Response_ForgotPasswordRequest',
|
||||
onSuccess: (resp) => {
|
||||
if (resp?.challengeEmail) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
}
|
||||
} else {
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
disconnect();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ 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';
|
||||
|
||||
|
|
@ -10,30 +11,28 @@ import { disconnect, updateStatus } from '.';
|
|||
export function forgotPasswordReset(options: WebSocketConnectOptions, passwordSalt?: string): void {
|
||||
const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams;
|
||||
|
||||
const forgotPasswordResetConfig: any = {
|
||||
const params: any = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
token,
|
||||
};
|
||||
|
||||
if (passwordSalt) {
|
||||
forgotPasswordResetConfig.hashedNewPassword = hashPassword(passwordSalt, newPassword);
|
||||
params.hashedNewPassword = hashPassword(passwordSalt, newPassword);
|
||||
} else {
|
||||
forgotPasswordResetConfig.newPassword = newPassword;
|
||||
params.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) {
|
||||
BackendService.sendSessionCommand('Command_ForgotPasswordReset', params, {
|
||||
onSuccess: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordSuccess();
|
||||
} else {
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
disconnect();
|
||||
disconnect();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function getGamesOfUser(userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetGamesOfUser.create({ userName });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_GetGamesOfUser.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
const response = raw['.Response_GetGamesOfUser.ext'];
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.getGamesOfUser(userName, response);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_GetGamesOfUser', { userName }, {
|
||||
responseName: 'Response_GetGamesOfUser',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.getGamesOfUser(userName, response);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function getUserInfo(userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_GetUserInfo.create({ userName });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_GetUserInfo.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { userInfo } = raw['.Response_GetUserInfo.ext'];
|
||||
SessionPersistence.getUserInfo(userInfo);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
|
||||
console.log('Not allowed');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to update information');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_GetUserInfo', { userName }, {
|
||||
responseName: 'Response_GetUserInfo',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.getUserInfo(response.userInfo);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@ 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 './forgotPasswordChallenge';
|
||||
export * from './forgotPasswordRequest';
|
||||
export * from './forgotPasswordReset';
|
||||
export * from './getGamesOfUser';
|
||||
|
|
@ -24,12 +23,8 @@ export * from './message';
|
|||
export * from './ping';
|
||||
export * from './register';
|
||||
export * from './removeFromList';
|
||||
export * from './replayDeleteMatch';
|
||||
export * from './replayList';
|
||||
export * from './replayModifyMatch';
|
||||
export * from './requestPasswordSalt';
|
||||
export * from './updateStatus';
|
||||
|
||||
/** TODO
|
||||
* REPLAY_DELETE_MATCH
|
||||
* REPLAY_DOWNLOAD
|
||||
* REPLAY_LIST
|
||||
* REPLAY_MODIFY_MATCH
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,37 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
|
||||
export function joinRoom(roomId: number): void {
|
||||
const command = webClient.protobuf.controller.Command_JoinRoom.create({ roomId });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_JoinRoom.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { roomInfo } = raw['.Response_JoinRoom.ext'];
|
||||
|
||||
RoomPersistence.joinRoom(roomInfo);
|
||||
return;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespNameNotFound:
|
||||
error = 'Failed to join the room: it doesn\'t exist on the server.';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespContextError:
|
||||
error = 'The server thinks you are in the room but Cockatrice is unable to display it. Try restarting Cockatrice.';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserLevelTooLow:
|
||||
error = 'You do not have the required permission to join this room.';
|
||||
break;
|
||||
default:
|
||||
error = 'Failed to join the room due to an unknown error.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_JoinRoom', { roomId }, {
|
||||
responseName: 'Response_JoinRoom',
|
||||
onSuccess: (response) => {
|
||||
RoomPersistence.joinRoom(response.roomInfo);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
|
||||
export function listRooms(): void {
|
||||
const command = webClient.protobuf.controller.Command_ListRooms.create();
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ListRooms.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc);
|
||||
BackendService.sendSessionCommand('Command_ListRooms', {}, {});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,11 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function listUsers(): void {
|
||||
const command = webClient.protobuf.controller.Command_ListUsers.create();
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ListUsers.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
const response = raw['.Response_ListUsers.ext'];
|
||||
|
||||
if (response) {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.updateUsers(response.userList);
|
||||
break;
|
||||
default:
|
||||
console.log(`Failed to fetch Server Rooms [${responseCode}] : `, raw);
|
||||
}
|
||||
}
|
||||
|
||||
BackendService.sendSessionCommand('Command_ListUsers', {}, {
|
||||
responseName: 'Response_ListUsers',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.updateUsers(response.userList);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { ProtoController } from '../../services/ProtoController';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
|
|
@ -25,13 +27,18 @@ export function login(options: WebSocketConnectOptions, passwordSalt?: string):
|
|||
loginConfig.password = password;
|
||||
}
|
||||
|
||||
const command = webClient.protobuf.controller.Command_Login.create(loginConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Login.ext': command });
|
||||
const { ResponseCode } = ProtoController.root.Response;
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const resp = raw['.Response_Login.ext'];
|
||||
const onLoginError = (message: string, extra?: () => void) => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, message);
|
||||
extra?.();
|
||||
SessionPersistence.loginFailed();
|
||||
disconnect();
|
||||
};
|
||||
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
BackendService.sendSessionCommand('Command_Login', loginConfig, {
|
||||
responseName: 'Response_Login',
|
||||
onSuccess: (resp) => {
|
||||
const { buddyList, ignoreList, userInfo } = resp;
|
||||
|
||||
SessionPersistence.updateBuddyList(buddyList);
|
||||
|
|
@ -43,50 +50,30 @@ export function login(options: WebSocketConnectOptions, passwordSalt?: string):
|
|||
listRooms();
|
||||
|
||||
updateStatus(StatusEnum.LOGGED_IN, 'Logged in.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespClientUpdateRequired:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing features');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWouldOverwriteOldSession:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: duplicated user session');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: banned user');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: registration required');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespClientIdRequired:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing client ID');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespContextError:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: server error');
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespAccountNotActivated:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: account not activated');
|
||||
SessionPersistence.accountAwaitingActivation(options);
|
||||
break;
|
||||
|
||||
default:
|
||||
updateStatus(StatusEnum.DISCONNECTED, `Login failed: unknown error: ${raw.responseCode}`);
|
||||
}
|
||||
|
||||
SessionPersistence.loginFailed();
|
||||
disconnect();
|
||||
},
|
||||
onResponseCode: {
|
||||
[ResponseCode.RespClientUpdateRequired]: () =>
|
||||
onLoginError('Login failed: missing features'),
|
||||
[ResponseCode.RespWrongPassword]: () =>
|
||||
onLoginError('Login failed: incorrect username or password'),
|
||||
[ResponseCode.RespUsernameInvalid]: () =>
|
||||
onLoginError('Login failed: incorrect username or password'),
|
||||
[ResponseCode.RespWouldOverwriteOldSession]: () =>
|
||||
onLoginError('Login failed: duplicated user session'),
|
||||
[ResponseCode.RespUserIsBanned]: () =>
|
||||
onLoginError('Login failed: banned user'),
|
||||
[ResponseCode.RespRegistrationRequired]: () =>
|
||||
onLoginError('Login failed: registration required'),
|
||||
[ResponseCode.RespClientIdRequired]: () =>
|
||||
onLoginError('Login failed: missing client ID'),
|
||||
[ResponseCode.RespContextError]: () =>
|
||||
onLoginError('Login failed: server error'),
|
||||
[ResponseCode.RespAccountNotActivated]: () =>
|
||||
onLoginError('Login failed: account not activated',
|
||||
() => SessionPersistence.accountAwaitingActivation(options)
|
||||
),
|
||||
},
|
||||
onError: (responseCode) =>
|
||||
onLoginError(`Login failed: unknown error: ${responseCode}`),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,10 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function message(userName: string, message: string): void {
|
||||
const command = webClient.protobuf.controller.Command_Message.create({ userName, message });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Message.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.directMessageSent(userName, message);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespNameNotFound:
|
||||
console.log('Name not found');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespInIgnoreList:
|
||||
console.log('On ignore list');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespChatFlood:
|
||||
console.log('Flooding chat');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
|
||||
console.log('Wrong password');
|
||||
break;
|
||||
default:
|
||||
console.log('Failed to send direct message');
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_Message', { userName, message }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.directMessageSent(userName, message);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
|
||||
export function ping(pingReceived: Function): void {
|
||||
const command = webClient.protobuf.controller.Command_Ping.create();
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Ping.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, pingReceived);
|
||||
BackendService.sendSessionCommand('Command_Ping', {}, {
|
||||
onResponse: (raw) => pingReceived(raw),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
import { ServerRegisterParams } from 'store';
|
||||
import { WebSocketConnectOptions } from 'types';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { ProtoController } from '../../services/ProtoController';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { hashPassword } from '../../utils';
|
||||
import NormalizeService from '../../utils/NormalizeService';
|
||||
|
||||
import { login, disconnect } from './';
|
||||
import { login, disconnect, updateStatus } from './';
|
||||
|
||||
export function register(options: WebSocketConnectOptions, passwordSalt?: string): void {
|
||||
const { userName, password, email, country, realName } = options as ServerRegisterParams;
|
||||
|
||||
const registerConfig: any = {
|
||||
const params: any = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
email,
|
||||
|
|
@ -20,55 +21,57 @@ export function register(options: WebSocketConnectOptions, passwordSalt?: string
|
|||
};
|
||||
|
||||
if (passwordSalt) {
|
||||
registerConfig.hashedPassword = hashPassword(passwordSalt, password);
|
||||
params.hashedPassword = hashPassword(passwordSalt, password);
|
||||
} else {
|
||||
registerConfig.password = password;
|
||||
params.password = password;
|
||||
}
|
||||
|
||||
const command = webClient.protobuf.controller.Command_Register.create(registerConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Register.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAccepted) {
|
||||
login(options, passwordSalt);
|
||||
SessionPersistence.registrationSuccess()
|
||||
return;
|
||||
}
|
||||
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation:
|
||||
SessionPersistence.accountAwaitingActivation(options);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserAlreadyExists:
|
||||
SessionPersistence.registrationUserNameError('Username is taken');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
|
||||
SessionPersistence.registrationUserNameError('Invalid username');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespPasswordTooShort:
|
||||
SessionPersistence.registrationPasswordError('Your password was too short');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespEmailRequiredToRegister:
|
||||
SessionPersistence.registrationRequiresEmail();
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespEmailBlackListed:
|
||||
SessionPersistence.registrationEmailError('This email provider has been blocked');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespTooManyRequests:
|
||||
SessionPersistence.registrationEmailError('Max accounts reached for this email');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled:
|
||||
SessionPersistence.registrationFailed('Registration is currently disabled');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned:
|
||||
SessionPersistence.registrationFailed(raw.reasonStr, raw.endTime);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed:
|
||||
default:
|
||||
SessionPersistence.registrationFailed('Registration failed due to a server issue');
|
||||
break;
|
||||
}
|
||||
const { ResponseCode } = ProtoController.root.Response;
|
||||
|
||||
const onRegistrationError = (action: () => void) => {
|
||||
action();
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Registration failed');
|
||||
disconnect();
|
||||
};
|
||||
|
||||
BackendService.sendSessionCommand('Command_Register', params, {
|
||||
onResponseCode: {
|
||||
[ResponseCode.RespRegistrationAccepted]: () => {
|
||||
login(options, passwordSalt);
|
||||
SessionPersistence.registrationSuccess();
|
||||
},
|
||||
[ResponseCode.RespRegistrationAcceptedNeedsActivation]: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Registration accepted, awaiting activation');
|
||||
SessionPersistence.accountAwaitingActivation(options);
|
||||
disconnect();
|
||||
},
|
||||
[ResponseCode.RespUserAlreadyExists]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationUserNameError('Username is taken')
|
||||
),
|
||||
[ResponseCode.RespUsernameInvalid]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationUserNameError('Invalid username')
|
||||
),
|
||||
[ResponseCode.RespPasswordTooShort]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationPasswordError('Your password was too short')
|
||||
),
|
||||
[ResponseCode.RespEmailRequiredToRegister]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationRequiresEmail()
|
||||
),
|
||||
[ResponseCode.RespEmailBlackListed]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationEmailError('This email provider has been blocked')
|
||||
),
|
||||
[ResponseCode.RespTooManyRequests]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationEmailError('Max accounts reached for this email')
|
||||
),
|
||||
[ResponseCode.RespRegistrationDisabled]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationFailed('Registration is currently disabled')
|
||||
),
|
||||
[ResponseCode.RespUserIsBanned]: (raw) => onRegistrationError(
|
||||
() => SessionPersistence.registrationFailed(raw.reasonStr, raw.endTime)
|
||||
),
|
||||
},
|
||||
onError: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationFailed('Registration failed due to a server issue')
|
||||
),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function removeFromBuddyList(userName: string): void {
|
||||
|
|
@ -10,16 +10,9 @@ export function removeFromIgnoreList(userName: string): void {
|
|||
}
|
||||
|
||||
export function removeFromList(list: string, userName: string): void {
|
||||
const command = webClient.protobuf.controller.Command_RemoveFromList.create({ list, userName });
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_RemoveFromList.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
SessionPersistence.removeFromList(list, userName);
|
||||
break;
|
||||
default:
|
||||
console.error('Failed to remove from list', responseCode);
|
||||
}
|
||||
BackendService.sendSessionCommand('Command_RemoveFromList', { list, userName }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.removeFromList(list, userName);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function replayDeleteMatch(gameId: number): void {
|
||||
BackendService.sendSessionCommand('Command_ReplayDeleteMatch', { gameId }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.replayDeleteMatch(gameId);
|
||||
},
|
||||
});
|
||||
}
|
||||
11
webclient/src/websocket/commands/session/replayList.ts
Normal file
11
webclient/src/websocket/commands/session/replayList.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function replayList(): void {
|
||||
BackendService.sendSessionCommand('Command_ReplayList', {}, {
|
||||
responseName: 'Response_ReplayList',
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.replayList(response.matchList);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { BackendService } from '../../services/BackendService';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function replayModifyMatch(gameId: number, doNotHide: boolean): void {
|
||||
BackendService.sendSessionCommand('Command_ReplayModifyMatch', { gameId, doNotHide }, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.replayModifyMatch(gameId, doNotHide);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ import { RequestPasswordSaltParams } from 'store';
|
|||
import { StatusEnum, WebSocketConnectOptions, WebSocketConnectReason } from 'types';
|
||||
|
||||
import webClient from '../../WebClient';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { ProtoController } from '../../services/ProtoController';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
import {
|
||||
|
|
@ -15,64 +17,48 @@ import {
|
|||
export function requestPasswordSalt(options: WebSocketConnectOptions): void {
|
||||
const { userName } = options as RequestPasswordSaltParams;
|
||||
|
||||
const registerConfig = {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
};
|
||||
|
||||
const command = webClient.protobuf.controller.Command_RequestPasswordSalt.create(registerConfig);
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_RequestPasswordSalt.ext': command });
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk: {
|
||||
const passwordSalt = raw['.Response_PasswordSalt.ext']?.passwordSalt;
|
||||
|
||||
switch (options.reason) {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
||||
activate(options, passwordSalt);
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.PASSWORD_RESET: {
|
||||
forgotPasswordReset(options, passwordSalt);
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.LOGIN:
|
||||
default: {
|
||||
login(options, passwordSalt);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired: {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: registration required');
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
|
||||
}
|
||||
}
|
||||
|
||||
const onFailure = () => {
|
||||
switch (options.reason) {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
SessionPersistence.accountActivationFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.PASSWORD_RESET: {
|
||||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
case WebSocketConnectReason.LOGIN:
|
||||
default: {
|
||||
default:
|
||||
SessionPersistence.loginFailed();
|
||||
}
|
||||
}
|
||||
|
||||
disconnect();
|
||||
};
|
||||
|
||||
BackendService.sendSessionCommand('Command_RequestPasswordSalt', {
|
||||
...webClient.clientConfig,
|
||||
userName,
|
||||
}, {
|
||||
responseName: 'Response_PasswordSalt',
|
||||
onSuccess: (resp) => {
|
||||
const passwordSalt = resp?.passwordSalt;
|
||||
|
||||
switch (options.reason) {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
activate(options, passwordSalt);
|
||||
break;
|
||||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
forgotPasswordReset(options, passwordSalt);
|
||||
break;
|
||||
default:
|
||||
login(options, passwordSalt);
|
||||
}
|
||||
},
|
||||
onResponseCode: {
|
||||
[ProtoController.root.Response.ResponseCode.RespRegistrationRequired]: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: registration required');
|
||||
onFailure();
|
||||
},
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
|
||||
onFailure();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue