import { Component, linkEvent } from "inferno"; import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { HttpService, UserService } from "../../services"; import { RequestState } from "../../services/HttpService"; import { capitalizeFirstLetter, myAuth, setIsoData } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; interface State { passwordChangeRes: RequestState; form: { token: string; password?: string; password_verify?: string; }; siteRes: GetSiteResponse; } export class PasswordChange extends Component { private isoData = setIsoData(this.context); state: State = { passwordChangeRes: { state: "empty" }, siteRes: this.isoData.site_res, form: { token: this.props.match.params.token, }, }; constructor(props: any, context: any) { super(props, context); } get documentTitle(): string { return `${i18n.t("password_change")} - ${ this.state.siteRes.site_view.site.name }`; } render() { return (
{i18n.t("password_change")}
{this.passwordChangeForm()}
); } passwordChangeForm() { return (
); } handlePasswordChange(i: PasswordChange, event: any) { i.state.form.password = event.target.value; i.setState(i.state); } handleVerifyPasswordChange(i: PasswordChange, event: any) { i.state.form.password_verify = event.target.value; i.setState(i.state); } async handlePasswordChangeSubmit(i: PasswordChange, event: any) { event.preventDefault(); i.setState({ passwordChangeRes: { state: "loading" } }); const password = i.state.form.password; const password_verify = i.state.form.password_verify; if (password && password_verify) { i.setState({ passwordChangeRes: await HttpService.client.passwordChangeAfterReset({ token: i.state.form.token, password, password_verify, }), }); if (i.state.passwordChangeRes.state === "success") { const data = i.state.passwordChangeRes.data; UserService.Instance.login(data); const site = await HttpService.client.getSite({ auth: myAuth() }); if (site.state === "success") { UserService.Instance.myUserInfo = site.data.my_user; } i.props.history.replace("/"); } } } }