Webatrice: fix saved password (#4563)

* fix saved label, and fix using hashedPassword when Save is unchecked

* update host only after successful login

* cleanup

* fix ability to deselect saved password on successful login

* cleanup

* clear options after connection

* fix registration saved username

* cleanup

* change label

* fix tests

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2022-02-27 10:12:38 -06:00 committed by GitHub
parent 9577ada171
commit 2a54e9d7d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 170 additions and 169 deletions

View file

@ -216,7 +216,7 @@ describe('SessionEvents', () => {
describe('.Event_ListRooms.ext', () => {
beforeEach(() => {
webClient.options.autojoinrooms = false;
webClient.clientOptions.autojoinrooms = false;
jest.spyOn(RoomPersistence, 'updateRooms').mockImplementation(() => {});
});
@ -229,7 +229,7 @@ describe('SessionEvents', () => {
});
it('should call SessionCommands.joinRoom if webClient and room is configured for autojoin', () => {
webClient.options.autojoinrooms = true;
webClient.clientOptions.autojoinrooms = true;
jest.spyOn(SessionCommands, 'joinRoom').mockImplementation(() => {});
const data: ListRoomsData = { roomList: [{ roomId, autoJoin: true } as any, { roomId: 2, autoJoin: false } as any] };
@ -291,6 +291,7 @@ describe('SessionEvents', () => {
jest.spyOn(SessionPersistence, 'updateInfo').mockImplementation(() => {});
webClient.protobuf.controller.Event_ServerIdentification = { ServerOptions: { SupportsPasswordHash: 1 } };
webClient.options = {};
});
it('update status/info and login', () => {

View file

@ -79,7 +79,7 @@ function connectionClosed({ reason, reasonStr }: ConnectionClosedData) {
function listRooms({ roomList }: ListRoomsData) {
RoomPersistence.updateRooms(roomList);
if (webClient.options.autojoinrooms) {
if (webClient.clientOptions.autojoinrooms) {
roomList.forEach(({ autoJoin, roomId }) => {
if (autoJoin) {
SessionCommands.joinRoom(roomId);
@ -120,45 +120,49 @@ function serverIdentification(info: ServerIdentificationData) {
return;
}
switch (webClient.options.reason) {
const getPasswordSalt = passwordSaltSupported(serverOptions, webClient);
const { options } = webClient;
switch (options.reason) {
case WebSocketConnectReason.LOGIN:
SessionCommands.updateStatus(StatusEnum.LOGGING_IN, 'Logging In...');
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.login();
SessionCommands.login(options);
}
break;
case WebSocketConnectReason.REGISTER:
const passwordSalt = passwordSaltSupported(serverOptions, webClient) ? generateSalt() : null;
SessionCommands.register(passwordSalt);
const passwordSalt = getPasswordSalt ? generateSalt() : null;
SessionCommands.register(options, passwordSalt);
break;
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.activateAccount();
SessionCommands.activateAccount(options);
}
break;
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
SessionCommands.resetPasswordRequest();
SessionCommands.resetPasswordRequest(options);
break;
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
SessionCommands.resetPasswordChallenge();
SessionCommands.resetPasswordChallenge(options);
break;
case WebSocketConnectReason.PASSWORD_RESET:
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
if (getPasswordSalt) {
SessionCommands.requestPasswordSalt(options);
} else {
SessionCommands.resetPassword();
SessionCommands.resetPassword(options);
}
break;
default:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + webClient.options.reason);
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + options.reason);
SessionCommands.disconnect();
break;
}
webClient.options = {};
SessionPersistence.updateInfo(serverName, serverVersion);
}