From 64b2ea3da4a65c5663e6d837ba0e11ef85c875a1 Mon Sep 17 00:00:00 2001 From: catarak Date: Sat, 27 Aug 2016 20:46:20 -0400 Subject: [PATCH] add and test logout --- client/components/Nav.js | 35 ++++++++++++++++++++---- client/modules/IDE/pages/IDEView.js | 8 ++++-- client/modules/User/actions.js | 13 +++++++++ client/modules/User/reducers.js | 4 +++ client/styles/base/_base.scss | 4 +++ client/styles/components/_nav.scss | 20 +++++++++++++- server/controllers/session.controller.js | 6 ++++ server/routes/session.routes.js | 2 ++ 8 files changed, 84 insertions(+), 8 deletions(-) diff --git a/client/components/Nav.js b/client/components/Nav.js index 527b9bbf..2da859e8 100644 --- a/client/components/Nav.js +++ b/client/components/Nav.js @@ -85,10 +85,34 @@ function Nav(props) { ); @@ -105,7 +129,8 @@ Nav.propTypes = { }).isRequired, project: PropTypes.shape({ id: PropTypes.string - }) + }), + logoutUser: PropTypes.func.isRequired }; export default Nav; diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js index d02a0cd5..965edc46 100644 --- a/client/modules/IDE/pages/IDEView.js +++ b/client/modules/IDE/pages/IDEView.js @@ -15,6 +15,7 @@ import * as IDEActions from '../actions/ide'; import * as ProjectActions from '../actions/project'; import * as EditorAccessibilityActions from '../actions/editorAccessibility'; import * as PreferencesActions from '../actions/preferences'; +import * as UserActions from '../../User/actions'; import { getFile, getHTMLFile, getJSFiles, getCSSFiles, setSelectedFile } from '../reducers/files'; import SplitPane from 'react-split-pane'; import Overlay from '../../App/components/Overlay'; @@ -117,6 +118,7 @@ class IDEView extends React.Component { exportProjectAsZip={this.props.exportProjectAsZip} cloneProject={this.props.cloneProject} project={this.props.project} + logoutUser={this.props.logoutUser} /> { + axios.get(`${ROOT_URL}/logout`, { withCredentials: true }) + .then(() => { + dispatch({ + type: ActionTypes.UNAUTH_USER + }); + }) + .catch(response => dispatch(authError(response.data.error))); + }; +} + diff --git a/client/modules/User/reducers.js b/client/modules/User/reducers.js index db3dac3e..c2f3f8ab 100644 --- a/client/modules/User/reducers.js +++ b/client/modules/User/reducers.js @@ -5,6 +5,10 @@ const user = (state = { authenticated: false }, action) => { case ActionTypes.AUTH_USER: return { ...action.user, authenticated: true }; + case ActionTypes.UNAUTH_USER: + return { + authenticated: false + }; case ActionTypes.AUTH_ERROR: return { authenticated: false diff --git a/client/styles/base/_base.scss b/client/styles/base/_base.scss index 29568ba3..dbf361c6 100644 --- a/client/styles/base/_base.scss +++ b/client/styles/base/_base.scss @@ -11,6 +11,10 @@ body, input, button { color: $light-primary-text-color; } +body { + background-color: $light-background-color; +} + .root-app, .app { min-height: 100%; height: 100%; diff --git a/client/styles/components/_nav.scss b/client/styles/components/_nav.scss index 64867783..940f6af0 100644 --- a/client/styles/components/_nav.scss +++ b/client/styles/components/_nav.scss @@ -1,6 +1,6 @@ .nav { width: 100%; - padding: #{10 / $base-font-size}rem #{40 / $base-font-size}rem; + padding: #{10 / $base-font-size}rem #{70 / $base-font-size}rem; padding-left: #{170 / $base-font-size}rem; display: flex; flex-direction: row; @@ -24,4 +24,22 @@ & + & { margin-left: #{20 / $base-font-size}rem; } + position: relative; + &:hover .nav__dropdown { + display: flex; + } +} + +.nav__dropdown { + display: none; + position: absolute; + flex-direction: column; + background-color: $light-background-color; + padding: #{10 / $base-font-size}rem; + left: #{-10 / $base-font-size}rem; + border: 1px solid $ide-border-color; + & li + li { + margin-top: #{10 / $base-font-size}rem; + } + width: #{140 / $base-font-size}rem; } \ No newline at end of file diff --git a/server/controllers/session.controller.js b/server/controllers/session.controller.js index cbee93f4..77a9e20c 100644 --- a/server/controllers/session.controller.js +++ b/server/controllers/session.controller.js @@ -30,3 +30,9 @@ export function getSession(req, res) { } return res.status(404).send({ message: 'Session does not exist' }); } + +export function destroySession(req, res) { + req.logout(); + res.json({success: true}); +} + diff --git a/server/routes/session.routes.js b/server/routes/session.routes.js index b0305d70..8b68cefd 100644 --- a/server/routes/session.routes.js +++ b/server/routes/session.routes.js @@ -7,6 +7,8 @@ router.route('/login').post(SessionController.createSession); router.route('/session').get(SessionController.getSession); +router.route('/logout').get(SessionController.destroySession); + export default router; // TODO add github authentication stuff