2022-06-21 21:42:29 +00:00
|
|
|
import { None } from "@sniptt/monads/build";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { Component } from "inferno";
|
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
GetSiteResponse,
|
2021-12-30 15:26:45 +00:00
|
|
|
UserOperation,
|
|
|
|
VerifyEmail as VerifyEmailForm,
|
|
|
|
VerifyEmailResponse,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-12-30 15:26:45 +00:00
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { WebSocketService } from "../../services";
|
|
|
|
import {
|
|
|
|
isBrowser,
|
|
|
|
setIsoData,
|
|
|
|
toast,
|
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
verifyEmailForm: VerifyEmailForm;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class VerifyEmail extends Component<any, State> {
|
|
|
|
private isoData = setIsoData(this.context);
|
|
|
|
private subscription: Subscription;
|
|
|
|
|
|
|
|
emptyState: State = {
|
2022-06-21 21:42:29 +00:00
|
|
|
verifyEmailForm: new VerifyEmailForm({
|
2021-12-30 15:26:45 +00:00
|
|
|
token: this.props.match.params.token,
|
2022-06-21 21:42:29 +00:00
|
|
|
}),
|
|
|
|
siteRes: this.isoData.site_res,
|
2021-12-30 15:26:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
|
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.verifyEmail(this.state.verifyEmailForm)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (isBrowser()) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.siteRes.site_view.match({
|
|
|
|
some: siteView => `${i18n.t("verify_email")} - ${siteView.site.name}`,
|
|
|
|
none: "",
|
|
|
|
});
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2021-12-30 15:26:45 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
2022-06-21 21:42:29 +00:00
|
|
|
description={None}
|
|
|
|
image={None}
|
2021-12-30 15:26:45 +00:00
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3 mb-4">
|
2021-12-30 15:26:45 +00:00
|
|
|
<h5>{i18n.t("verify_email")}</h5>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
|
|
|
console.log(msg);
|
|
|
|
if (msg.error) {
|
|
|
|
toast(i18n.t(msg.error), "danger");
|
|
|
|
this.setState(this.state);
|
|
|
|
this.props.history.push("/");
|
|
|
|
return;
|
|
|
|
} else if (op == UserOperation.VerifyEmail) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<VerifyEmailResponse>(msg, VerifyEmailResponse);
|
2021-12-30 15:26:45 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("email_verified"));
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(this.emptyState);
|
2021-12-30 15:26:45 +00:00
|
|
|
this.props.history.push("/login");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|