Skip to content

Commit

Permalink
refactor(oauth2): remove external log out action
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsut committed Oct 28, 2020
1 parent 95b3129 commit e9bc889
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 47 deletions.
6 changes: 0 additions & 6 deletions webapp/app/containers/App/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
GET_EXTERNAL_AUTH_PROVIDERS,
GET_EXTERNAL_AUTH_PROVIDERS_SUCESS,
TRY_EXTERNAL_AUTH,
EXTERNAL_AUTH_LOGOUT,
GET_SERVER_CONFIGURATIONS,
GET_SERVER_CONFIGURATIONS_SUCCESS,
GET_SERVER_CONFIGURATIONS_FAIL,
Expand Down Expand Up @@ -94,11 +93,6 @@ export function tryExternalAuth(resolve) {
}
}
}
export function externalAuthlogout() {
return {
type: EXTERNAL_AUTH_LOGOUT
}
}

export function login(username, password, resolve) {
return {
Expand Down
1 change: 0 additions & 1 deletion webapp/app/containers/App/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
export const GET_EXTERNAL_AUTH_PROVIDERS = 'davinci/App/GET_EXTERNAL_AUTH_PROVIDERS'
export const GET_EXTERNAL_AUTH_PROVIDERS_SUCESS = 'davinci/App/GET_EXTERNAL_AUTH_PROVIDERS_SUCESS'
export const TRY_EXTERNAL_AUTH = 'davinci/App/TRY_EXTERNAL_AUTH'
export const EXTERNAL_AUTH_LOGOUT = 'davinci/App/EXTERNAL_AUTH_LOGOUT'
export const LOGIN = 'davinci/App/LOGIN'
export const LOGGED = 'davinci/App/LOGGED'
export const LOGIN_ERROR = 'davinci/App/LOGIN_ERROR'
Expand Down
6 changes: 0 additions & 6 deletions webapp/app/containers/App/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
DOWNLOAD_FILE,
GET_EXTERNAL_AUTH_PROVIDERS,
TRY_EXTERNAL_AUTH,
EXTERNAL_AUTH_LOGOUT,
GET_CAPTCHA_FOR_RESET_PASSWORD,
RESET_PASSWORD_UNLOGGED,
GET_USER_BY_TOKEN
Expand Down Expand Up @@ -154,10 +153,6 @@ export function* login(action) {
}
}

export function* externalAuthlogout() {
location.replace(`${api.externalLogout}`)
}

export function* logout() {
try {
removeToken()
Expand Down Expand Up @@ -415,7 +410,6 @@ export default function* rootGroupSaga() {
takeEvery(ACTIVE, activeUser),
takeLatest(GET_EXTERNAL_AUTH_PROVIDERS, getExternalAuthProviders),
takeEvery(TRY_EXTERNAL_AUTH, tryExternalAuth),
takeEvery(EXTERNAL_AUTH_LOGOUT, externalAuthlogout),
takeEvery(LOGIN, login),
takeEvery(LOGOUT, logout),
takeEvery(UPDATE_PROFILE, updateProfile),
Expand Down
7 changes: 7 additions & 0 deletions webapp/app/containers/App/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ const makeSelectVersion = () =>
(globalState) => globalState.version
)

const makeSelectOauth2Enabled = () =>
createSelector(
selectGlobal,
(globalState) => globalState.oauth2Enabled
)

export {
selectGlobal,
makeSelectVersion,
makeSelectOauth2Enabled,
makeSelectExternalAuthProviders,
makeSelectLogged,
makeSelectLoginUser,
Expand Down
22 changes: 12 additions & 10 deletions webapp/app/containers/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ import LoginForm from './LoginForm'
import { compose } from 'redux'

import { login, logged } from '../App/actions'
import { makeSelectLoginLoading } from '../App/selectors'
import {
makeSelectLoginLoading,
makeSelectOauth2Enabled
} from '../App/selectors'
import checkLogin from 'utils/checkLogin'
import { setToken } from 'utils/request'
import { statistic } from 'utils/statistic/statistic.dv'
import ExternalLogin from '../ExternalLogin'

const styles = require('./Login.less')

interface ILoginProps {
loginLoading: boolean
onLogged: (user) => void
onLogin: (username: string, password: string, resolve: () => any) => any
}
type MappedStates = ReturnType<typeof mapStateToProps>
type MappedDispatches = ReturnType<typeof mapDispatchToProps>
type ILoginProps = MappedStates & MappedDispatches

interface ILoginStates {
username: string
Expand Down Expand Up @@ -122,7 +123,7 @@ export class Login extends React.PureComponent<
}

public render() {
const { loginLoading } = this.props
const { loginLoading, oauth2Enabled } = this.props
const { username, password } = this.state
return (
<div className={styles.window}>
Expand Down Expand Up @@ -151,19 +152,20 @@ export class Login extends React.PureComponent<
忘记密码?
</a>
</p>
<ExternalLogin />
{oauth2Enabled && <ExternalLogin />}
</div>
)
}
}

const mapStateToProps = createStructuredSelector({
loginLoading: makeSelectLoginLoading()
loginLoading: makeSelectLoginLoading(),
oauth2Enabled: makeSelectOauth2Enabled()
})

export function mapDispatchToProps(dispatch) {
return {
onLogin: (username, password, resolve) =>
onLogin: (username: string, password: string, resolve: () => void) =>
dispatch(login(username, password, resolve)),
onLogged: (user) => dispatch(logged(user))
}
Expand Down
38 changes: 15 additions & 23 deletions webapp/app/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { createStructuredSelector } from 'reselect'

import Navigator from 'components/Navigator'

import { logged, logout, loadDownloadList, externalAuthlogout } from '../App/actions'
import { makeSelectLogged, makeSelectNavigator } from '../App/selectors'
import { DOWNLOAD_LIST_POLLING_FREQUENCY } from 'app/globalConstants'
import { logged, logout, loadDownloadList } from '../App/actions'
import { makeSelectLogged, makeSelectNavigator, makeSelectOauth2Enabled } from '../App/selectors'
import { DOWNLOAD_LIST_POLLING_FREQUENCY, EXTERNAL_LOG_OUT_URL } from 'app/globalConstants'

import { Project, ProjectList } from 'containers/Projects/Loadable'

Expand All @@ -53,19 +53,11 @@ import { NoAuthorization } from 'containers/NoAuthorization/Loadable'

const styles = require('./Main.less')

interface IMainProps {
logged: boolean
navigator: boolean
onLogged: (user) => void
onLogout: () => void
onExternalAuthLogout: () => void
onLoadDownloadList: () => void
}
type MappedStates = ReturnType<typeof mapStateToProps>
type MappedDispatches = ReturnType<typeof mapDispatchToProps>
type IMainProps = MappedStates & MappedDispatches & RouteComponentWithParams

export class Main extends React.Component<
IMainProps & RouteComponentWithParams,
{}
> {
export class Main extends React.Component<IMainProps, {}> {
private downloadListPollingTimer: number

constructor(props: IMainProps & RouteComponentWithParams) {
Expand All @@ -87,10 +79,13 @@ export class Main extends React.Component<
}

private logout = () => {
const { history, onLogout , onExternalAuthLogout } = this.props
const { history, oauth2Enabled, onLogout } = this.props
onLogout()
onExternalAuthLogout()
history.replace('/login')
if (oauth2Enabled) {
history.replace(EXTERNAL_LOG_OUT_URL)
} else {
history.replace('/login')
}
}

private renderAccount = () => (
Expand Down Expand Up @@ -193,19 +188,16 @@ export class Main extends React.Component<

const mapStateToProps = createStructuredSelector({
logged: makeSelectLogged(),
oauth2Enabled: makeSelectOauth2Enabled(),
navigator: makeSelectNavigator()
})

export function mapDispatchToProps(dispatch) {
return {
onLogged: (user) => dispatch(logged(user)),
onLogout: () => dispatch(logout()),
onExternalAuthLogout: () => dispatch(externalAuthlogout()),
onLoadDownloadList: () => dispatch(loadDownloadList())
}
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(Main)
export default connect(mapStateToProps, mapDispatchToProps)(Main)
1 change: 1 addition & 0 deletions webapp/app/globalConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
export const CLIENT_VERSION = '0.3-beta.9'
export const API_HOST = '/api/v3'
export const SHARE_HOST = `${location.origin}/share.html`
export const EXTERNAL_LOG_OUT_URL = '/login/oauth2/logout'

const defaultEchartsTheme = require('assets/json/echartsThemes/default.project.json')
export const DEFAULT_ECHARTS_THEME = defaultEchartsTheme.theme
Expand Down
1 change: 0 additions & 1 deletion webapp/app/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { API_HOST } from '../globalConstants'
export default {
externalAuthProviders: `${API_HOST}/login/getOauth2Clients`,
tryExternalAuth: `${API_HOST}/login/externalLogin`,
externalLogout: `/login/oauth2/logout`,
login: `${API_HOST}/login`,
group: `${API_HOST}/groups`,
user: `${API_HOST}/users`,
Expand Down

0 comments on commit e9bc889

Please sign in to comment.