1 import { Component, linkEvent } from "inferno";
2 import { Subscription } from "rxjs";
6 PasswordChange as PasswordChangeForm,
8 } from "lemmy-js-client";
9 import { WebSocketService, UserService } from "../services";
12 capitalizeFirstLetter,
20 import { i18n } from "../i18next";
21 import { HtmlTags } from "./html-tags";
22 import { Spinner } from "./icon";
25 passwordChangeForm: PasswordChangeForm;
30 export class PasswordChange extends Component<any, State> {
31 private isoData = setIsoData(this.context);
32 private subscription: Subscription;
36 token: this.props.match.params.token,
38 password_verify: undefined,
41 site_view: this.isoData.site_res.site_view,
44 constructor(props: any, context: any) {
45 super(props, context);
47 this.state = this.emptyState;
49 this.parseMessage = this.parseMessage.bind(this);
50 this.subscription = wsSubscribe(this.parseMessage);
53 componentWillUnmount() {
55 this.subscription.unsubscribe();
59 get documentTitle(): string {
60 return `${i18n.t("password_change")} - ${this.state.site_view.site.name}`;
65 <div class="container">
67 title={this.documentTitle}
68 path={this.context.router.route.match.url}
71 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
72 <h5>{i18n.t("password_change")}</h5>
73 {this.passwordChangeForm()}
80 passwordChangeForm() {
82 <form onSubmit={linkEvent(this, this.handlePasswordChangeSubmit)}>
83 <div class="form-group row">
84 <label class="col-sm-2 col-form-label" htmlFor="new-password">
85 {i18n.t("new_password")}
87 <div class="col-sm-10">
91 value={this.state.passwordChangeForm.password}
92 onInput={linkEvent(this, this.handlePasswordChange)}
98 <div class="form-group row">
99 <label class="col-sm-2 col-form-label" htmlFor="verify-password">
100 {i18n.t("verify_password")}
102 <div class="col-sm-10">
106 value={this.state.passwordChangeForm.password_verify}
107 onInput={linkEvent(this, this.handleVerifyPasswordChange)}
113 <div class="form-group row">
114 <div class="col-sm-10">
115 <button type="submit" class="btn btn-secondary">
116 {this.state.loading ? (
119 capitalizeFirstLetter(i18n.t("save"))
128 handlePasswordChange(i: PasswordChange, event: any) {
129 i.state.passwordChangeForm.password = event.target.value;
133 handleVerifyPasswordChange(i: PasswordChange, event: any) {
134 i.state.passwordChangeForm.password_verify = event.target.value;
138 handlePasswordChangeSubmit(i: PasswordChange, event: any) {
139 event.preventDefault();
140 i.state.loading = true;
143 WebSocketService.Instance.send(
144 wsClient.passwordChange(i.state.passwordChangeForm)
148 parseMessage(msg: any) {
149 let op = wsUserOp(msg);
151 toast(i18n.t(msg.error), "danger");
152 this.state.loading = false;
153 this.setState(this.state);
155 } else if (op == UserOperation.PasswordChange) {
156 let data = wsJsonToRes<LoginResponse>(msg).data;
157 this.state = this.emptyState;
158 this.setState(this.state);
159 UserService.Instance.login(data);
160 this.props.history.push("/");