-
- parseMessage(msg: any) {
- const op = wsUserOp(msg);
- console.log(msg);
- if (msg.error) {
- toast(i18n.t(msg.error), "danger");
- this.setState(s => ((s.form.captcha_answer = undefined), s));
- // Refetch another captcha
- // WebSocketService.Instance.send(wsClient.getCaptcha());
- return;
- } else {
- if (op == UserOperation.Register) {
- const data = wsJsonToRes<LoginResponse>(msg);
- // Only log them in if a jwt was set
- if (data.jwt) {
- UserService.Instance.login(data);
- this.props.history.push("/communities");
- location.reload();
- } else {
- if (data.verify_email_sent) {
- toast(i18n.t("verify_email_sent"));
- }
- if (data.registration_created) {
- toast(i18n.t("registration_application_sent"));
- }
- this.props.history.push("/");
- }
- } else if (op == UserOperation.GetCaptcha) {
- const data = wsJsonToRes<GetCaptchaResponse>(msg);
- if (data.ok) {
- this.setState({ captcha: data });
- this.setState(s => ((s.form.captcha_uuid = data.ok?.uuid), s));
- }
- } else if (op == UserOperation.PasswordReset) {
- toast(i18n.t("reset_password_mail_sent"));
- } else if (op == UserOperation.GetSite) {
- const data = wsJsonToRes<GetSiteResponse>(msg);
- this.setState({ siteRes: data });
- }
- }
- }