feat: email verification

This commit is contained in:
Hasta Ragil Saputra 2019-01-29 15:12:06 +07:00
parent 327e01ef9e
commit 2f4c76d48a
2 changed files with 46 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import withStyles from "@material-ui/core/styles/withStyles"; import withStyles from "@material-ui/core/styles/withStyles";
import {styles} from '../Register/registerStyle'; import {styles} from '../Register/registerStyle';
import {notification} from 'antd';
import Grid from '@material-ui/core/Grid'; import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper'; import Paper from '@material-ui/core/Paper';
@ -43,7 +44,39 @@ class BTNLoginPage extends React.Component{
this.authStore = props.appstate.auth; this.authStore = props.appstate.auth;
} }
handleChange = name => event => { componentDidMount() {
const urlParams = new URLSearchParams(window.location.search);
if(urlParams.has('key')) {
this.setState({
isLoading: true
});
this.authStore.verifyEmail(urlParams.get('key')).then((res) => {
if(res.login_request_id) {
notification.open({
message: 'Email Verification',
description: 'Email verification success'
});
this.setState({
isLoading: false
});
//redirect to otp page
} else {
notification.open({
message: 'Email Verification',
description: res.message
});
this.setState({
isLoading: false
});
// res.message
}
})
}
}
handleChange = name => event => {
this.setState({ this.setState({
[name]: event.target.value, [name]: event.target.value,
}); });
@ -131,7 +164,7 @@ class BTNLoginPage extends React.Component{
</Hidden> </Hidden>
<Grid item xs={12} sm={12} md={6} style={{paddingLeft : 50,paddingRight : 50}}> <Grid item xs={12} sm={12} md={6} style={{paddingLeft : 50,paddingRight : 50}}>
{ {
this.state.isNeedEmailVerification && this.state.isNeedEmailVerification &&
<Paper className={classes.formRegister}> <Paper className={classes.formRegister}>
<Typography variant="h6" gutterBottom> <Typography variant="h6" gutterBottom>
Your account still need email verification Your account still need email verification
@ -139,7 +172,7 @@ class BTNLoginPage extends React.Component{
<Typography variant="subtitle2" gutterBottom> <Typography variant="subtitle2" gutterBottom>
Still not received any email? <Link to={"/register"}>Resend email</Link> Still not received any email? <Link to={"/register"}>Resend email</Link>
</Typography> </Typography>
<div style={{padding : 5,marginTop : 20}}> <div style={{padding : 5,marginTop : 20}}>
<Button onClick={() => this.setState({isNeedEmailVerification : false})} fullWidth variant="contained" style={{background:'#ffeb3b'}}> <Button onClick={() => this.setState({isNeedEmailVerification : false})} fullWidth variant="contained" style={{background:'#ffeb3b'}}>
Back to Login Back to Login
@ -149,7 +182,7 @@ class BTNLoginPage extends React.Component{
} }
{ {
!this.state.isNeedEmailVerification && !this.state.isNeedEmailVerification &&
<Paper className={classes.formRegister}> <Paper className={classes.formRegister}>
<Typography variant="h6" gutterBottom> <Typography variant="h6" gutterBottom>
Login to BTN Point Login to BTN Point
@ -195,7 +228,7 @@ class BTNLoginPage extends React.Component{
</div> </div>
</Paper> </Paper>
} }
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
@ -205,4 +238,4 @@ class BTNLoginPage extends React.Component{
} }
} }
export default withStyles(styles)(BTNLoginPage); export default withStyles(styles)(BTNLoginPage);

View File

@ -73,6 +73,13 @@ export class Authentication {
}) })
} }
@action
verifyEmail(key) {
return this.http.post('authentication/email_verification', {
key
})
}
@action @action
logout() { logout() {
this.context.setToken(""); this.context.setToken("");