fixed redirect reset password

This commit is contained in:
britea 2020-03-26 08:34:21 +01:00
parent f0c429b9a3
commit 5712483efb
2 changed files with 16 additions and 28 deletions

View file

@ -1,21 +1,8 @@
import React from "react";
import {
Dropdown,
Icon,
Grid,
Divider,
Button,
Label,
Responsive,
} from "semantic-ui-react";
import { Grid, Divider, Button, Label, Responsive } from "semantic-ui-react";
import { Segment, Image } from "semantic-ui-react";
import { BrowserView, MobileView } from "react-device-detect";
import { call } from "../client_server";
const AvatarImage = () => (
<Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered />
);
const IconHomeImage = () => (
<Image
src="smart-home.png"

View file

@ -20,6 +20,7 @@ export default class ChangePass extends Component {
state: false,
message: "",
},
success: false,
};
this.handleChangePassword = this.handleChangePassword.bind(this);
}
@ -30,8 +31,12 @@ export default class ChangePass extends Component {
this.setState({ [nam]: val });
};
checkpassword = (e) => {
if (e.target.value !== this.state.password) {
handleChangePassword = (e) => {
const params = {
confirmationToken: this.props.query.token,
password: this.state.password,
};
if (this.state.confirmPassword !== this.state.password) {
this.setState({
error: {
state: true,
@ -39,22 +44,15 @@ export default class ChangePass extends Component {
},
});
}
};
handleChangePassword = (e) => {
const params = {
confirmationToken: this.props.query.token,
password: this.state.password,
};
call
.resetPassword(params)
.then((res) => {
if (res.status !== 200) {
this.setState({ error: { state: true, message: "Errore" } });
if (res.status === 200) {
this.setState({ success: true });
} else {
return <Redirect to="/" />;
this.setState({ error: { state: true, message: "Errore" } });
}
// else set a message that an email has been sent
})
.catch((err) => {
console.log(err);
@ -62,6 +60,9 @@ export default class ChangePass extends Component {
};
render() {
if (this.state.success) {
return <Redirect to="/login" />;
}
return (
<React.Fragment>
<Button circular style={{ margin: "2em" }} href="/">
@ -100,9 +101,9 @@ export default class ChangePass extends Component {
icon="address card outline"
iconPosition="left"
placeholder="Confirm Password"
name="confirm-password"
name="confirmPassword"
type="password"
onChange={this.checkpassword}
onChange={this.onChangeHandler}
required
/>
<Button