From 97a92cb8dbc163049b72190e568880e6aa81f4df Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 23 Mar 2022 14:48:45 -0600 Subject: [PATCH 1/6] update login and register page to not display if already logged in --- webapp/src/pages/loginPage.tsx | 10 ++++++++-- webapp/src/pages/registerPage.tsx | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/webapp/src/pages/loginPage.tsx b/webapp/src/pages/loginPage.tsx index 7f5513d8d..afe967b70 100644 --- a/webapp/src/pages/loginPage.tsx +++ b/webapp/src/pages/loginPage.tsx @@ -4,8 +4,8 @@ import React, {useState} from 'react' import {useHistory, Link} from 'react-router-dom' import {FormattedMessage} from 'react-intl' -import {useAppDispatch} from '../store/hooks' -import {fetchMe} from '../store/users' +import {useAppDispatch, useAppSelector} from '../store/hooks' +import {fetchMe, getLoggedIn} from '../store/users' import Button from '../widgets/buttons/button' import client from '../octoClient' @@ -17,6 +17,7 @@ const LoginPage = () => { const [errorMessage, setErrorMessage] = useState('') const history = useHistory() const dispatch = useAppDispatch() + const loggedIn = useAppSelector(getLoggedIn) const handleLogin = async (): Promise => { const logged = await client.login(username, password) @@ -28,6 +29,11 @@ const LoginPage = () => { } } + if (loggedIn) { + history.replace('/') + return null + } + return (
{ const [errorMessage, setErrorMessage] = useState('') const history = useHistory() const dispatch = useAppDispatch() + const loggedIn = useAppSelector(getLoggedIn) const handleRegister = async (): Promise => { const queryString = new URLSearchParams(window.location.search) @@ -37,6 +38,11 @@ const RegisterPage = () => { } } + if (loggedIn) { + history.replace('/') + return null + } + return (
Date: Wed, 30 Mar 2022 10:49:39 -0600 Subject: [PATCH 2/6] update pages to use , clear state when logging out --- webapp/src/components/sidebar/sidebarUserMenu.tsx | 6 ++++-- webapp/src/pages/loginPage.tsx | 5 ++--- webapp/src/pages/registerPage.tsx | 5 ++--- webapp/src/store/users.ts | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/webapp/src/components/sidebar/sidebarUserMenu.tsx b/webapp/src/components/sidebar/sidebarUserMenu.tsx index be031600f..c56e2b9d0 100644 --- a/webapp/src/components/sidebar/sidebarUserMenu.tsx +++ b/webapp/src/components/sidebar/sidebarUserMenu.tsx @@ -11,8 +11,8 @@ import {IUser} from '../../user' import FocalboardLogoIcon from '../../widgets/icons/focalboard_logo' import Menu from '../../widgets/menu' import MenuWrapper from '../../widgets/menuWrapper' -import {getMe} from '../../store/users' -import {useAppSelector} from '../../store/hooks' +import {getMe, setMe} from '../../store/users' +import {useAppSelector, useAppDispatch} from '../../store/hooks' import {Utils} from '../../utils' import ModalWrapper from '../modalWrapper' @@ -26,6 +26,7 @@ import './sidebarUserMenu.scss' declare let window: IAppWindow const SidebarUserMenu = () => { + const dispatch = useAppDispatch() const history = useHistory() const [showRegistrationLinkDialog, setShowRegistrationLinkDialog] = useState(false) const user = useAppSelector(getMe) @@ -60,6 +61,7 @@ const SidebarUserMenu = () => { name={intl.formatMessage({id: 'Sidebar.logout', defaultMessage: 'Log out'})} onClick={async () => { await octoClient.logout() + dispatch(setMe(null)) history.push('/login') }} /> diff --git a/webapp/src/pages/loginPage.tsx b/webapp/src/pages/loginPage.tsx index afe967b70..4b65df9c0 100644 --- a/webapp/src/pages/loginPage.tsx +++ b/webapp/src/pages/loginPage.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useState} from 'react' -import {useHistory, Link} from 'react-router-dom' +import {useHistory, Link, Redirect} from 'react-router-dom' import {FormattedMessage} from 'react-intl' import {useAppDispatch, useAppSelector} from '../store/hooks' @@ -30,8 +30,7 @@ const LoginPage = () => { } if (loggedIn) { - history.replace('/') - return null + return } return ( diff --git a/webapp/src/pages/registerPage.tsx b/webapp/src/pages/registerPage.tsx index 39c41db84..bb8c56095 100644 --- a/webapp/src/pages/registerPage.tsx +++ b/webapp/src/pages/registerPage.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useState} from 'react' -import {useHistory, Link} from 'react-router-dom' +import {useHistory, Link, Redirect} from 'react-router-dom' import {FormattedMessage} from 'react-intl' import {useAppDispatch, useAppSelector} from '../store/hooks' @@ -39,8 +39,7 @@ const RegisterPage = () => { } if (loggedIn) { - history.replace('/') - return null + return } return ( diff --git a/webapp/src/store/users.ts b/webapp/src/store/users.ts index efb09f58f..6983ec226 100644 --- a/webapp/src/store/users.ts +++ b/webapp/src/store/users.ts @@ -44,8 +44,9 @@ const usersSlice = createSlice({ name: 'users', initialState, reducers: { - setMe: (state, action: PayloadAction) => { + setMe: (state, action: PayloadAction) => { state.me = action.payload + state.loggedIn = Boolean(state.me) }, setBoardUsers: (state, action: PayloadAction) => { state.boardUsers = action.payload.reduce((acc: {[key: string]: IUser}, user: IUser) => { From cafc65a5d8685b215402c49b36f4df9e0ff77652 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 30 Mar 2022 15:01:12 -0600 Subject: [PATCH 3/6] cypress tests must logout before attempting to login again --- app-config.json | 4 ++-- webapp/cypress.json | 2 +- webapp/cypress/config.json | 4 ++-- webapp/cypress/integration/loginActions.ts | 15 +++++++++++---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app-config.json b/app-config.json index 60ca2a134..ca6d016b5 100644 --- a/app-config.json +++ b/app-config.json @@ -1,6 +1,6 @@ { - "serverRoot": "http://localhost:8088", - "port": 8088, + "serverRoot": "http://localhost:8000", + "port": 8000, "dbtype": "sqlite3", "dbconfig": "./focalboard.db", "useSSL": false, diff --git a/webapp/cypress.json b/webapp/cypress.json index 538f7b0d2..51d0402c2 100644 --- a/webapp/cypress.json +++ b/webapp/cypress.json @@ -1,6 +1,6 @@ { "chromeWebSecurity": false, - "baseUrl": "http://localhost:8088", + "baseUrl": "http://localhost:8000", "testFiles": [ "**/login*.ts", "**/create*.ts", diff --git a/webapp/cypress/config.json b/webapp/cypress/config.json index db2a01f1d..a9d50ec01 100644 --- a/webapp/cypress/config.json +++ b/webapp/cypress/config.json @@ -1,6 +1,6 @@ { - "serverRoot": "http://localhost:8088", - "port": 8088, + "serverRoot": "http://localhost:8000", + "port": 8000, "dbtype": "sqlite3", "dbconfig": "file::memory:?cache=shared&_busy_timeout=5000", "useSSL": false, diff --git a/webapp/cypress/integration/loginActions.ts b/webapp/cypress/integration/loginActions.ts index 34c05578c..8a25c29d6 100644 --- a/webapp/cypress/integration/loginActions.ts +++ b/webapp/cypress/integration/loginActions.ts @@ -58,10 +58,12 @@ describe('Login actions', () => { cy.get('button').contains('Change password').click() cy.get('.succeeded').click() workspaceIsAvailable() - + logoutUser() + // Can log in user with new password cy.log('**Can log in user with new password**') loginUser(newPassword).then(() => resetPassword(newPassword)) + logoutUser() // Can't register second user without invite link cy.log('**Can\'t register second user without invite link**') @@ -85,9 +87,7 @@ describe('Login actions', () => { cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => { // Log out existing user - cy.log('**Log out existing user**') - cy.get('.Sidebar .SidebarUserMenu').click() - cy.get('.menu-name').contains('Log out').click() + logoutUser() // Register a new user cy.log('**Register new user**') @@ -114,6 +114,13 @@ describe('Login actions', () => { return workspaceIsAvailable() } + const logoutUser = () => { + cy.log('**Log out existing user**') + cy.get('.SidebarUserMenu').click() + cy.get('.menu-name').contains('Log out').click() + cy.location('pathname').should('eq', '/login') + } + const resetPassword = (oldPassword: string) => { cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password)) } From 1b353f13f240c1d797406fe6bbdc31e7173974b9 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 30 Mar 2022 15:04:18 -0600 Subject: [PATCH 4/6] cypress tests must logout before attempting to login again --- webapp/cypress/integration/loginActions.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/webapp/cypress/integration/loginActions.ts b/webapp/cypress/integration/loginActions.ts index 8a25c29d6..34c05578c 100644 --- a/webapp/cypress/integration/loginActions.ts +++ b/webapp/cypress/integration/loginActions.ts @@ -58,12 +58,10 @@ describe('Login actions', () => { cy.get('button').contains('Change password').click() cy.get('.succeeded').click() workspaceIsAvailable() - logoutUser() - + // Can log in user with new password cy.log('**Can log in user with new password**') loginUser(newPassword).then(() => resetPassword(newPassword)) - logoutUser() // Can't register second user without invite link cy.log('**Can\'t register second user without invite link**') @@ -87,7 +85,9 @@ describe('Login actions', () => { cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => { // Log out existing user - logoutUser() + cy.log('**Log out existing user**') + cy.get('.Sidebar .SidebarUserMenu').click() + cy.get('.menu-name').contains('Log out').click() // Register a new user cy.log('**Register new user**') @@ -114,13 +114,6 @@ describe('Login actions', () => { return workspaceIsAvailable() } - const logoutUser = () => { - cy.log('**Log out existing user**') - cy.get('.SidebarUserMenu').click() - cy.get('.menu-name').contains('Log out').click() - cy.location('pathname').should('eq', '/login') - } - const resetPassword = (oldPassword: string) => { cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password)) } From f66bed59a8184c00fcc08096e3180e5313546840 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 30 Mar 2022 15:12:56 -0600 Subject: [PATCH 5/6] revert bad config changes --- app-config.json | 4 ++-- webapp/cypress.json | 2 +- webapp/cypress/config.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app-config.json b/app-config.json index ca6d016b5..60ca2a134 100644 --- a/app-config.json +++ b/app-config.json @@ -1,6 +1,6 @@ { - "serverRoot": "http://localhost:8000", - "port": 8000, + "serverRoot": "http://localhost:8088", + "port": 8088, "dbtype": "sqlite3", "dbconfig": "./focalboard.db", "useSSL": false, diff --git a/webapp/cypress.json b/webapp/cypress.json index 51d0402c2..538f7b0d2 100644 --- a/webapp/cypress.json +++ b/webapp/cypress.json @@ -1,6 +1,6 @@ { "chromeWebSecurity": false, - "baseUrl": "http://localhost:8000", + "baseUrl": "http://localhost:8088", "testFiles": [ "**/login*.ts", "**/create*.ts", diff --git a/webapp/cypress/config.json b/webapp/cypress/config.json index a9d50ec01..db2a01f1d 100644 --- a/webapp/cypress/config.json +++ b/webapp/cypress/config.json @@ -1,6 +1,6 @@ { - "serverRoot": "http://localhost:8000", - "port": 8000, + "serverRoot": "http://localhost:8088", + "port": 8088, "dbtype": "sqlite3", "dbconfig": "file::memory:?cache=shared&_busy_timeout=5000", "useSSL": false, From 1741f1f01d1fe8939e5f5a14a9523c7dc9385b3f Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Wed, 30 Mar 2022 15:17:39 -0600 Subject: [PATCH 6/6] update cypress tests --- webapp/cypress/integration/loginActions.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/webapp/cypress/integration/loginActions.ts b/webapp/cypress/integration/loginActions.ts index 34c05578c..2d950f80c 100644 --- a/webapp/cypress/integration/loginActions.ts +++ b/webapp/cypress/integration/loginActions.ts @@ -58,10 +58,12 @@ describe('Login actions', () => { cy.get('button').contains('Change password').click() cy.get('.succeeded').click() workspaceIsAvailable() + logoutUser() // Can log in user with new password cy.log('**Can log in user with new password**') loginUser(newPassword).then(() => resetPassword(newPassword)) + logoutUser() // Can't register second user without invite link cy.log('**Can\'t register second user without invite link**') @@ -84,10 +86,7 @@ describe('Login actions', () => { cy.get('.Button').contains('Copied').should('exist') cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => { - // Log out existing user - cy.log('**Log out existing user**') - cy.get('.Sidebar .SidebarUserMenu').click() - cy.get('.menu-name').contains('Log out').click() + logoutUser() // Register a new user cy.log('**Register new user**') @@ -114,6 +113,13 @@ describe('Login actions', () => { return workspaceIsAvailable() } + const logoutUser = () => { + cy.log('**Log out existing user**') + cy.get('.SidebarUserMenu').click() + cy.get('.menu-name').contains('Log out').click() + cy.location('pathname').should('eq', '/login') + } + const resetPassword = (oldPassword: string) => { cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password)) }