1 import { Component, linkEvent } from 'inferno';
2 import { Subscription } from 'rxjs';
3 import { retryWhen, delay, take } from 'rxjs/operators';
8 } from '../interfaces';
9 import { WebSocketService, UserService } from '../services';
10 import { msgOp, capitalizeFirstLetter } from '../utils';
11 import { i18n } from '../i18next';
12 import { T } from 'inferno-i18next';
15 passwordChangeForm: PasswordChangeForm;
19 export class PasswordChange extends Component<any, State> {
20 private subscription: Subscription;
24 token: this.props.match.params.token,
26 password_verify: undefined,
31 constructor(props: any, context: any) {
32 super(props, context);
34 this.state = this.emptyState;
36 this.subscription = WebSocketService.Instance.subject
46 msg => this.parseMessage(msg),
47 err => console.error(err),
48 () => console.log('complete')
52 componentWillUnmount() {
53 this.subscription.unsubscribe();
57 document.title = `${i18n.t('password_change')} - ${
58 WebSocketService.Instance.site.name
64 <div class="container">
66 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
68 <T i18nKey="password_change">#</T>
70 {this.passwordChangeForm()}
77 passwordChangeForm() {
79 <form onSubmit={linkEvent(this, this.handlePasswordChangeSubmit)}>
80 <div class="form-group row">
81 <label class="col-sm-2 col-form-label">
82 <T i18nKey="new_password">#</T>
84 <div class="col-sm-10">
87 value={this.state.passwordChangeForm.password}
88 onInput={linkEvent(this, this.handlePasswordChange)}
94 <div class="form-group row">
95 <label class="col-sm-2 col-form-label">
96 <T i18nKey="verify_password">#</T>
98 <div class="col-sm-10">
101 value={this.state.passwordChangeForm.password_verify}
102 onInput={linkEvent(this, this.handleVerifyPasswordChange)}
108 <div class="form-group row">
109 <div class="col-sm-10">
110 <button type="submit" class="btn btn-secondary">
111 {this.state.loading ? (
112 <svg class="icon icon-spinner spin">
113 <use xlinkHref="#icon-spinner"></use>
116 capitalizeFirstLetter(i18n.t('save'))
125 handlePasswordChange(i: PasswordChange, event: any) {
126 i.state.passwordChangeForm.password = event.target.value;
130 handleVerifyPasswordChange(i: PasswordChange, event: any) {
131 i.state.passwordChangeForm.password_verify = event.target.value;
135 handlePasswordChangeSubmit(i: PasswordChange, event: any) {
136 event.preventDefault();
137 i.state.loading = true;
140 WebSocketService.Instance.passwordChange(i.state.passwordChangeForm);
143 parseMessage(msg: any) {
144 let op: UserOperation = msgOp(msg);
146 alert(i18n.t(msg.error));
147 this.state.loading = false;
148 this.setState(this.state);
151 if (op == UserOperation.PasswordChange) {
152 this.state = this.emptyState;
153 this.setState(this.state);
154 let res: LoginResponse = msg;
155 UserService.Instance.login(res);
156 this.props.history.push('/');