Add button to log out all sessions

This commit is contained in:
Tanner Collin 2020-01-23 03:32:54 +00:00
parent 664859dd26
commit b840889379
2 changed files with 44 additions and 1 deletions

View File

@ -1,10 +1,51 @@
import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import './light.css';
import { Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { BasicTable, staticUrl, requester } from './utils.js';
import { LoginForm, SignupForm } from './LoginSignup.js';
function LogoutEverywhere(props) {
const { token } = props;
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [yousure, setYousure] = useState(false);
const history = useHistory();
const handleClick = () => {
if (yousure) {
setLoading(true);
requester('/rest-auth/logout/', 'POST', token, {})
.then(res => {
setYousure(false);
history.push('/');
window.scrollTo(0, 0);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
} else {
setYousure(true);
}
};
return (
<div>
<Header size='medium'>Log Out from Everywhere</Header>
<p>Use this to log out from all sessions on all computers.</p>
{error && <p>Error, something went wrong.</p>}
<Button onClick={handleClick} loading={loading}>
{yousure ? 'You Sure?' : 'Log Out Everywhere'}
</Button>
</div>
);
};
function ChangePasswordForm(props) {
const { token } = props;
const [input, setInput] = useState({});
@ -194,6 +235,7 @@ export function Account(props) {
</Grid.Column>
<Grid.Column>
<Segment padded><ChangePasswordForm {...props} /></Segment>
<Segment padded><LogoutEverywhere {...props} /></Segment>
</Grid.Column>
</Grid>
</Container>

View File

@ -47,6 +47,7 @@ function App() {
setUserCache(false);
setYousure(false);
history.push('/');
window.scrollTo(0, 0);
} else {
setYousure(true);
}