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,
19 import { i18n } from '../i18next';
20 import { HtmlTags } from './html-tags';
23 passwordChangeForm: PasswordChangeForm;
28 export class PasswordChange extends Component<any, State> {
29 private isoData = setIsoData(this.context);
30 private subscription: Subscription;
34 token: this.props.match.params.token,
36 password_verify: undefined,
39 site_view: this.isoData.site_res.site_view,
42 constructor(props: any, context: any) {
43 super(props, context);
45 this.state = this.emptyState;
47 this.parseMessage = this.parseMessage.bind(this);
48 this.subscription = wsSubscribe(this.parseMessage);
51 componentWillUnmount() {
53 this.subscription.unsubscribe();
57 get documentTitle(): string {
58 return `${i18n.t('password_change')} - ${this.state.site_view.site.name}`;
63 <div class="container">
65 title={this.documentTitle}
66 path={this.context.router.route.match.url}
69 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
70 <h5>{i18n.t('password_change')}</h5>
71 {this.passwordChangeForm()}
78 passwordChangeForm() {
80 <form onSubmit={linkEvent(this, this.handlePasswordChangeSubmit)}>
81 <div class="form-group row">
82 <label class="col-sm-2 col-form-label">
83 {i18n.t('new_password')}
85 <div class="col-sm-10">
88 value={this.state.passwordChangeForm.password}
89 onInput={linkEvent(this, this.handlePasswordChange)}
95 <div class="form-group row">
96 <label class="col-sm-2 col-form-label">
97 {i18n.t('verify_password')}
99 <div class="col-sm-10">
102 value={this.state.passwordChangeForm.password_verify}
103 onInput={linkEvent(this, this.handleVerifyPasswordChange)}
109 <div class="form-group row">
110 <div class="col-sm-10">
111 <button type="submit" class="btn btn-secondary">
112 {this.state.loading ? (
113 <svg class="icon icon-spinner spin">
114 <use xlinkHref="#icon-spinner"></use>
117 capitalizeFirstLetter(i18n.t('save'))
126 handlePasswordChange(i: PasswordChange, event: any) {
127 i.state.passwordChangeForm.password = event.target.value;
131 handleVerifyPasswordChange(i: PasswordChange, event: any) {
132 i.state.passwordChangeForm.password_verify = event.target.value;
136 handlePasswordChangeSubmit(i: PasswordChange, event: any) {
137 event.preventDefault();
138 i.state.loading = true;
141 WebSocketService.Instance.client.passwordChange(i.state.passwordChangeForm);
144 parseMessage(msg: any) {
145 let op = wsUserOp(msg);
147 toast(i18n.t(msg.error), 'danger');
148 this.state.loading = false;
149 this.setState(this.state);
151 } else if (op == UserOperation.PasswordChange) {
152 let data = wsJsonToRes<LoginResponse>(msg).data;
153 this.state = this.emptyState;
154 this.setState(this.state);
155 UserService.Instance.login(data);
156 this.props.history.push('/');