2020-03-05 10:03:44 +00:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react';
|
2020-03-14 14:48:33 +00:00
|
|
|
import {Redirect } from "react-router-dom";
|
2020-03-07 09:54:42 +00:00
|
|
|
import { call } from '../client_server';
|
2020-03-05 10:03:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
export default class ForgotPass extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
user: "",
|
|
|
|
error: {
|
|
|
|
state: false,
|
|
|
|
message: "",
|
2020-03-14 14:48:33 +00:00
|
|
|
},
|
|
|
|
success: false,
|
2020-03-05 10:03:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeHandler = (event) => {
|
|
|
|
let nam = event.target.name;
|
|
|
|
let val = event.target.value;
|
|
|
|
this.setState({[nam]: val});
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSendEmail = (e) => {
|
2020-03-07 09:54:42 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const params = {
|
|
|
|
"email" : this.state.user,
|
|
|
|
}
|
2020-03-05 10:03:44 +00:00
|
|
|
|
2020-03-07 09:54:42 +00:00
|
|
|
call.initResetPassword(params)
|
|
|
|
.then(res => {
|
2020-03-14 14:48:33 +00:00
|
|
|
console.log(res);
|
|
|
|
if (res.status === 200) {
|
|
|
|
this.setState({success : true});
|
|
|
|
}
|
2020-03-07 09:54:42 +00:00
|
|
|
if (res.status === "Errore") {
|
|
|
|
this.setState({ error: { state: true,
|
|
|
|
message: "Errore"}});
|
|
|
|
}
|
|
|
|
//set a message that an email has been sent
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2020-03-05 10:03:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2020-03-14 14:48:33 +00:00
|
|
|
if (this.state.success) {
|
|
|
|
return <Redirect to="sent-email" />
|
|
|
|
}
|
2020-03-05 10:03:44 +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}>
|
|
|
|
<Message
|
|
|
|
error
|
|
|
|
header='Send E-mail Error'
|
|
|
|
content= {this.state.error.message}
|
|
|
|
/>
|
|
|
|
<Form.Input
|
|
|
|
icon='address card outline'
|
|
|
|
iconPosition='left'
|
|
|
|
placeholder='Username or E-mail'
|
|
|
|
name="user"
|
|
|
|
type='text'
|
|
|
|
onChange={this.onChangeHandler}
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<Button color='blue' fluid size='large' onClick={this.handleSendEmail}>
|
|
|
|
Send E-mail
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|