2020-03-23 20:24:17 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Form,
|
|
|
|
Grid,
|
|
|
|
Header,
|
|
|
|
Image,
|
|
|
|
Icon,
|
|
|
|
Message,
|
|
|
|
} from "semantic-ui-react";
|
|
|
|
import { call } from "../client_server";
|
2020-03-19 10:52:13 +00:00
|
|
|
import { Redirect } from "react-router-dom";
|
2020-03-05 10:03:44 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
export default class ChangePass extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
password: "",
|
|
|
|
error: {
|
|
|
|
state: false,
|
|
|
|
message: "",
|
|
|
|
},
|
2020-03-26 07:34:21 +00:00
|
|
|
success: false,
|
2020-03-23 20:24:17 +00:00
|
|
|
};
|
|
|
|
this.handleChangePassword = this.handleChangePassword.bind(this);
|
|
|
|
}
|
2020-03-05 10:03:44 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
onChangeHandler = (event) => {
|
|
|
|
let nam = event.target.name;
|
|
|
|
let val = event.target.value;
|
|
|
|
this.setState({ [nam]: val });
|
|
|
|
};
|
|
|
|
|
2020-03-26 07:34:21 +00:00
|
|
|
handleChangePassword = (e) => {
|
|
|
|
const params = {
|
|
|
|
confirmationToken: this.props.query.token,
|
|
|
|
password: this.state.password,
|
|
|
|
};
|
|
|
|
if (this.state.confirmPassword !== this.state.password) {
|
2020-03-23 20:24:17 +00:00
|
|
|
this.setState({
|
|
|
|
error: {
|
|
|
|
state: true,
|
|
|
|
message: "Passwords do not match.",
|
|
|
|
},
|
|
|
|
});
|
2020-03-05 10:03:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
call
|
|
|
|
.resetPassword(params)
|
|
|
|
.then((res) => {
|
2020-03-26 07:34:21 +00:00
|
|
|
if (res.status === 200) {
|
|
|
|
this.setState({ success: true });
|
2020-03-23 20:24:17 +00:00
|
|
|
} else {
|
2020-03-26 07:34:21 +00:00
|
|
|
this.setState({ error: { state: true, message: "Errore" } });
|
2020-03-05 10:03:44 +00:00
|
|
|
}
|
2020-03-23 20:24:17 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
2020-03-05 10:03:44 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
render() {
|
2020-03-26 07:34:21 +00:00
|
|
|
if (this.state.success) {
|
|
|
|
return <Redirect to="/login" />;
|
|
|
|
}
|
2020-03-23 20:24:17 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<Button circular style={{ margin: "2em" }} href="/">
|
|
|
|
<Icon name="arrow alternate circle left" />
|
|
|
|
Go Home{" "}
|
|
|
|
</Button>
|
|
|
|
<Grid
|
|
|
|
textAlign="center"
|
|
|
|
style={{ height: "70vh" }}
|
|
|
|
verticalAlign="middle"
|
|
|
|
>
|
|
|
|
<Grid.Column style={{ maxWidth: 450 }}>
|
|
|
|
<Header as="h2" color="blue" textAlign="center">
|
|
|
|
<Image src="img/logo.png" /> Reset Password
|
|
|
|
</Header>
|
|
|
|
<Form
|
|
|
|
size="large"
|
|
|
|
style={{ marginTop: "2em" }}
|
|
|
|
error={this.state.error.state}
|
2020-03-05 10:03:44 +00:00
|
|
|
>
|
2020-03-23 20:24:17 +00:00
|
|
|
<Message
|
|
|
|
error
|
|
|
|
header="Change Password Error"
|
|
|
|
content={this.state.error.message}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
icon="address card outline"
|
|
|
|
iconPosition="left"
|
|
|
|
placeholder="Reset your password"
|
|
|
|
name="password"
|
|
|
|
type="password"
|
|
|
|
onChange={this.onChangeHandler}
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
icon="address card outline"
|
|
|
|
iconPosition="left"
|
|
|
|
placeholder="Confirm Password"
|
2020-03-26 07:34:21 +00:00
|
|
|
name="confirmPassword"
|
2020-03-23 20:24:17 +00:00
|
|
|
type="password"
|
2020-03-26 07:34:21 +00:00
|
|
|
onChange={this.onChangeHandler}
|
2020-03-23 20:24:17 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
color="blue"
|
|
|
|
fluid
|
|
|
|
size="large"
|
|
|
|
onClick={this.handleChangePassword}
|
|
|
|
>
|
|
|
|
Confirm password
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|