mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
connect reset password to login view (#4489)
This commit is contained in:
parent
811ee54c76
commit
1f15445c69
31 changed files with 893 additions and 445 deletions
|
|
@ -38,6 +38,8 @@ export class WebClient {
|
|||
hashedPassword: '',
|
||||
newPassword: '',
|
||||
email: '',
|
||||
realName: '',
|
||||
country: '',
|
||||
clientid: null,
|
||||
reason: null,
|
||||
autojoinrooms: true,
|
||||
|
|
|
|||
|
|
@ -299,39 +299,300 @@ describe('SessionCommands', () => {
|
|||
sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
|
||||
})
|
||||
|
||||
it('should login user if registration accepted without email verification', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
|
||||
describe('RespRegistrationAccepted', () => {
|
||||
it('should call SessionCommands.login()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
SessionCommands.register();
|
||||
expect(SessionCommands.login).toHaveBeenCalled();
|
||||
|
||||
expect(SessionCommands.login).toHaveBeenCalled();
|
||||
expect(SessionPersistence.accountAwaitingActivation).not.toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
|
||||
it('should prompt user if registration accepted with email verification', () => {
|
||||
describe('RespRegistrationAcceptedNeedsActivation', () => {
|
||||
const RespRegistrationAcceptedNeedsActivation = 'RespRegistrationAcceptedNeedsActivation';
|
||||
response.responseCode = RespRegistrationAcceptedNeedsActivation;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation =
|
||||
RespRegistrationAcceptedNeedsActivation;
|
||||
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespRegistrationAcceptedNeedsActivation;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation =
|
||||
RespRegistrationAcceptedNeedsActivation;
|
||||
});
|
||||
|
||||
SessionCommands.register();
|
||||
it('should call SessionPersistence.accountAwaitingActivation()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalled();
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should disconnect user if registration fails due to registration being disabled', () => {
|
||||
describe('RespUserAlreadyExists', () => {
|
||||
const RespUserAlreadyExists = 'RespUserAlreadyExists';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespUserAlreadyExists;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespUserAlreadyExists =
|
||||
RespUserAlreadyExists;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationUserNameError()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationUserNameError').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespUsernameInvalid', () => {
|
||||
const RespUsernameInvalid = 'RespUsernameInvalid';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespUsernameInvalid;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid =
|
||||
RespUsernameInvalid;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationUserNameError()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationUserNameError').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespPasswordTooShort', () => {
|
||||
const RespPasswordTooShort = 'RespPasswordTooShort';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespPasswordTooShort;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespPasswordTooShort =
|
||||
RespPasswordTooShort;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationPasswordError()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationPasswordError').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationPasswordError).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespEmailRequiredToRegister', () => {
|
||||
const RespEmailRequiredToRegister = 'RespEmailRequiredToRegister';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespEmailRequiredToRegister;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespEmailRequiredToRegister =
|
||||
RespEmailRequiredToRegister;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationRequiresEmail()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationRequiresEmail').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationRequiresEmail).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespEmailBlackListed', () => {
|
||||
const RespEmailBlackListed = 'RespEmailBlackListed';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespEmailBlackListed;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespEmailBlackListed =
|
||||
RespEmailBlackListed;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationEmailError()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationEmailError').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationEmailError).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespTooManyRequests', () => {
|
||||
const RespTooManyRequests = 'RespTooManyRequests';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespTooManyRequests;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespTooManyRequests =
|
||||
RespTooManyRequests;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationEmailError()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationEmailError').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationEmailError).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespRegistrationDisabled', () => {
|
||||
const RespRegistrationDisabled = 'RespRegistrationDisabled';
|
||||
response.responseCode = RespRegistrationDisabled;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled = RespRegistrationDisabled;
|
||||
|
||||
SessionCommands.register();
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespRegistrationDisabled;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled =
|
||||
RespRegistrationDisabled;
|
||||
});
|
||||
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, expect.any(String));
|
||||
it('should call SessionPersistence.registrationFailed()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespUserIsBanned', () => {
|
||||
const RespUserIsBanned = 'RespUserIsBanned';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespUserIsBanned;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned =
|
||||
RespUserIsBanned;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationFailed()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RespRegistrationFailed', () => {
|
||||
const RespRegistrationFailed = 'RespRegistrationFailed';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = RespRegistrationFailed;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed =
|
||||
RespRegistrationFailed;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationFailed()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('UnknownFailureReason', () => {
|
||||
const UnknownFailureReason = 'UnknownFailureReason';
|
||||
|
||||
beforeEach(() => {
|
||||
response.responseCode = UnknownFailureReason;
|
||||
webClient.protobuf.controller.Response.ResponseCode.UnknownFailureReason =
|
||||
UnknownFailureReason;
|
||||
});
|
||||
|
||||
it('should call SessionPersistence.registrationFailed()', () => {
|
||||
jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
|
||||
jest.spyOn(SessionPersistence, 'registrationFailed').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.login).not.toHaveBeenCalled();
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
|
||||
SessionCommands.register();
|
||||
|
||||
expect(SessionCommands.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -179,48 +179,41 @@ export class SessionCommands {
|
|||
return;
|
||||
}
|
||||
|
||||
let error;
|
||||
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation:
|
||||
SessionPersistence.accountAwaitingActivation();
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled:
|
||||
error = 'Registration is currently disabled';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserAlreadyExists:
|
||||
error = 'There is already an existing user with this username';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespEmailRequiredToRegister:
|
||||
error = 'A valid email address is required to register';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespEmailBlackListed:
|
||||
error = 'The email address provider used has been blocked from use';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespTooManyRequests:
|
||||
error = 'This email address already has the maximum number of accounts you can register';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespPasswordTooShort:
|
||||
error = 'Your password was too short';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned:
|
||||
error = NormalizeService.normalizeBannedUserError(raw.reasonStr, raw.endTime);
|
||||
SessionPersistence.registrationUserNameError('Username is taken');
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
|
||||
console.error('ResponseCode.RespUsernameInvalid', raw.reasonStr);
|
||||
error = 'Invalid username';
|
||||
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(NormalizeService.normalizeBannedUserError(raw.reasonStr, raw.endTime));
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed:
|
||||
default:
|
||||
console.error('ResponseCode Type', raw.responseCode);
|
||||
error = 'Registration failed due to a server issue';
|
||||
SessionPersistence.registrationFailed('Registration failed due to a server issue');
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, `Registration Failed: ${error}`);
|
||||
}
|
||||
|
||||
SessionCommands.disconnect();
|
||||
});
|
||||
};
|
||||
|
|
@ -272,14 +265,14 @@ export class SessionCommands {
|
|||
const resp = raw['.Response_ForgotPasswordRequest.ext'];
|
||||
|
||||
if (resp.challengeEmail) {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Requesting MFA information');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password reset in progress');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
}
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password reset failed, please try again');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +298,10 @@ export class SessionCommands {
|
|||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password reset in progress');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password reset failed, please try again');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
|
|
@ -335,10 +328,10 @@ export class SessionCommands {
|
|||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password successfully updated');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordSuccess();
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Password update failed, please try again');
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,26 @@ export class SessionPersistence {
|
|||
console.log('Account activation failed, show an action here');
|
||||
}
|
||||
|
||||
static registrationRequiresEmail() {
|
||||
ServerDispatch.registrationRequiresEmail();
|
||||
}
|
||||
|
||||
static registrationFailed(error: string) {
|
||||
ServerDispatch.registrationFailed(error);
|
||||
}
|
||||
|
||||
static registrationEmailError(error: string) {
|
||||
ServerDispatch.registrationEmailError(error);
|
||||
}
|
||||
|
||||
static registrationPasswordError(error: string) {
|
||||
ServerDispatch.registrationPasswordError(error);
|
||||
}
|
||||
|
||||
static registrationUserNameError(error: string) {
|
||||
ServerDispatch.registrationUserNameError(error);
|
||||
}
|
||||
|
||||
static resetPasswordChallenge() {
|
||||
ServerDispatch.resetPasswordChallenge();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue