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

View file

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