add logout in system and if not isnotlogin go to register

This commit is contained in:
enggar_ganteng 2019-02-01 15:01:34 +07:00
parent 12e7f13c1a
commit b5b9cd1187
3 changed files with 107 additions and 93 deletions

View File

@ -73,6 +73,7 @@ import CartIcon from '@material-ui/icons/ShoppingCart';
import NotificationsIcon from '@material-ui/icons/Notifications';
import MoreIcon from '@material-ui/icons/MoreVert';
import CancelIcon from '@material-ui/icons/Cancel';
import ListIcon from '@material-ui/icons/FormatListBulleted';
import { styles } from './styles';
import Drawer from '@material-ui/core/Drawer';
@ -237,26 +238,26 @@ class App extends React.Component {
}
willLogout() {
// Modal.confirm({
// title: 'Log out the system?',
// content: 'Are sure sure you want to log out the system?',
// okText: 'Confirm',
// cancelText: 'Cancel',
// visible: this.state.visible,
// zIndex: 3000,
// onOk: () => {
// this.authStore.logout();
// this.setState({
// visible: false,
// redirect: true
// });
// },
// onCancel: () => {
// this.setState({
// visible: false,
// });
// }
// });
Modal.confirm({
title: 'Log out the system?',
content: 'Are sure sure you want to log out the system?',
okText: 'Confirm',
cancelText: 'Cancel',
visible: this.state.visible,
zIndex: 3000,
onOk: () => {
this.authStore.logout();
this.setState({
visible: false,
redirect: true
});
},
onCancel: () => {
this.setState({
visible: false,
});
}
});
}
openCreateProjectDialog() {
@ -404,9 +405,12 @@ class App extends React.Component {
</Link>
<Link onClick={this
.changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}>
<MenuItem>Sign Out</MenuItem>
.bind(this, '/app/transaction')} to={LINKS.TRANSACTION}>
<MenuItem>Transaction</MenuItem>
</Link>
{/* <Link onClick={this.willLogout.bind(this)}> */}
<MenuItem onClick={this.willLogout.bind(this)}>Sign Out</MenuItem>
{/* </Link> */}
</Menu>
);
@ -448,14 +452,24 @@ class App extends React.Component {
</Link>
<Link onClick={this
.changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}>
.bind(this, '/transaction')} to={LINKS.TRANSACTION}>
<MenuItem>
<IconButton color="inherit">
<ListIcon />
</IconButton>
<p>Transaction</p>
</MenuItem>
</Link>
{/* <Link onClick={this
.changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}> */}
<MenuItem onClick={this.willLogout.bind(this)}>
<IconButton color="inherit">
<CancelIcon />
</IconButton>
<p>Sign Out</p>
</MenuItem>
</Link>
{/* </Link> */}
</Menu>
);

View File

@ -145,9 +145,9 @@ export default class Routes extends React.Component {
<Route
{...rest}
render={
(props) => true === true
(props) => this.authStore.isLoggedIn === true
? (<Component {...props}/>)
: (<Redirect to={{pathname : LINKS.LOGIN}}/>
: (<Redirect to={{pathname : LINKS.REGISTER}}/>
)
}
/>

View File

@ -86,29 +86,29 @@ export class Authentication {
logout() {
this.context.setToken("");
this.context.setUserData({});
// return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')})
// .then(res => {
// this.context.setToken("");
// this.context.setUserData({});
//
// localStorage.removeItem('id_token');
// localStorage.removeItem('user.name');
// localStorage.removeItem('user.profile_image');
// localStorage.setItem('isLoggingIn', false);
// let cookies = document.cookie.split(";");
// for (let i = 0; i < cookies.length; i++) {
// this.eraseCookie(cookies[i].split("=")[0]);
// }
//
// if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) {
// window.Tawk_API.hideWidget()
// }
//
// return res;
// })
// .catch(err => {
// throw err;
// })
return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')})
.then(res => {
this.context.setToken("");
this.context.setUserData({});
localStorage.removeItem('id_token');
localStorage.removeItem('user.name');
localStorage.removeItem('user.profile_image');
localStorage.setItem('isLoggingIn', false);
let cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
this.eraseCookie(cookies[i].split("=")[0]);
}
if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) {
window.Tawk_API.hideWidget()
}
return res;
})
.catch(err => {
throw err;
})
}