From b840889379e979cf2ca26d1faa4ea285618227d1 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 23 Jan 2020 03:32:54 +0000 Subject: [PATCH] Add button to log out all sessions --- webclient/src/Account.js | 44 +++++++++++++++++++++++++++++++++++++++- webclient/src/App.js | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/webclient/src/Account.js b/webclient/src/Account.js index 2b8c071..aaba18a 100644 --- a/webclient/src/Account.js +++ b/webclient/src/Account.js @@ -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 ( +
+
Log Out from Everywhere
+ +

Use this to log out from all sessions on all computers.

+ + {error &&

Error, something went wrong.

} + + +
+ ); +}; + function ChangePasswordForm(props) { const { token } = props; const [input, setInput] = useState({}); @@ -194,6 +235,7 @@ export function Account(props) { + diff --git a/webclient/src/App.js b/webclient/src/App.js index d5c2f0d..1e145d6 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -47,6 +47,7 @@ function App() { setUserCache(false); setYousure(false); history.push('/'); + window.scrollTo(0, 0); } else { setYousure(true); }