Skip to content

Commit

Permalink
feat: add log out
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmacdonald committed Jul 11, 2019
1 parent d4d5ab9 commit 0171db6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/LogOut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

let $ = window.cwrcQuery
if ($ === undefined) {
let prevJQuery = window.jQuery
$ = require('jquery')
window.jQuery = $
require('bootstrap')
window.jQuery = prevJQuery
window.cwrcQuery = $
}

let Cookies = require('js-cookie');

import React, {Component, Fragment} from 'react'
import { Modal, Button } from 'react-bootstrap';

function doLogOut() {
Cookies.remove('cwrc-token');
window.location.reload();
}

class LogOutDialog extends Component {
constructor(props) {
super(props);
}

render() {
const handleClose = this.props.handleClose;
return (
<Fragment>
<Modal.Header>CWRC-Writer Logout</Modal.Header>
<Modal.Body>
<Fragment>
<p>You are about to log out of CWRC-Writer (i.e. revoke the GitHub authentication). Any unsaved changes will be lost.</p>
<p>Do you want to continue?</p>
</Fragment>
</Modal.Body>
<Modal.Footer>
<Button onClick={handleClose}>
No, Cancel and Return
</Button>
<Button bsStyle="success" onClick={doLogOut}>
Yes, Log Out
</Button>
</Modal.Footer>
</Fragment>
)
}
}

export default LogOutDialog
20 changes: 19 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import queryString from 'query-string';

import Splash from './Splash.js';
import { AuthenticateDialog, isAuthenticated } from './authenticate.js';
import LogOutDialog from './LogOut.js';
import LoadDialog from './Load.js';
import SaveCmp from './Save.js';

Expand Down Expand Up @@ -83,6 +84,15 @@ function loadWrap(writer, shouldOverwrite = false) {
$('#'+dialogId).addClass('cwrc');
}

function logOutWrap() {
ReactDOM.render(
<GitDialog action="logout" />,
document.querySelector('#'+renderId)
);
dialogInstance.setState({show: true,});
$('#'+dialogId).addClass('cwrc');
}

function getUserInfo() {
return _userInfo;
}
Expand Down Expand Up @@ -297,6 +307,13 @@ class GitDialog extends Component {
<SaveCmp user={user.userId} owner={owner} repo={repoName} path={path} handleClose={this.handleClose} getDocument={getDocument} handleRepoChange={setRepo} handlePathChange={setPath} handleSaved={this.handleSaved} />
</Modal>
)

case 'logout':
return (
<Modal id={dialogId} show={true} animation={false}>
<LogOutDialog handleClose={this.handleClose} />
</Modal>
)
}
}
}
Expand All @@ -306,5 +323,6 @@ export {
saveWrap as save,
loadWrap as load,
getUserInfo,
getDocumentURI
getDocumentURI,
logOutWrap as logOut
}

0 comments on commit 0171db6

Please sign in to comment.