diff --git a/webui/src/actions/auth.js b/webui/src/actions/auth.js index 22508a8a2..626f7f985 100644 --- a/webui/src/actions/auth.js +++ b/webui/src/actions/auth.js @@ -1,5 +1,3 @@ -import { createAction } from 'redux-actions'; - export const AUTH = { LOGIN_REQUEST: 'auth/LOGIN_REQUEST', LOGIN_SUCCESS: 'auth/LOGIN_SUCCESS', @@ -7,26 +5,11 @@ export const AUTH = { LOGOUT: 'auth/LOGOUT' } -/* - AuthAction.loginRequest - payload : { - username, - password - } +function action(type, payload = {}) { + return {type, ...payload} +} - AuthAction.loginSuccess - payload : { - username, - role - } - - AuthAction.loginFailure - payload : null - - AuthAction.logout - payload : null -*/ -export const loginRequest = createAction(AUTH.LOGIN_REQUEST); -export const loginSuccess = createAction(AUTH.LOGIN_SUCCESS); -export const loginFailure = createAction(AUTH.LOGIN_FAILURE); -export const logout = createAction(AUTH.LOGOUT); \ No newline at end of file +export const loginRequest = (username, password) => action(AUTH.LOGIN_REQUEST, {username, password}) +export const loginSuccess = (username, role) => action(AUTH.LOGIN_SUCCESS, {username, role}) +export const loginFailure = () => action(AUTH.LOGIN_FAILURE) +export const logout = () => action(AUTH.LOGOUT) \ No newline at end of file diff --git a/webui/src/actions/ui.js b/webui/src/actions/ui.js index 7d20b2025..03889f7cd 100644 --- a/webui/src/actions/ui.js +++ b/webui/src/actions/ui.js @@ -3,7 +3,8 @@ import { createAction } from 'redux-actions'; export const UI = { TOGGLE_SIDEBAR: 'ui/TOGGLE_SIDEBAR', SET_SIDEBAR_VISIBILITY: 'ui/SET_SIDEBAR_VISIBILITY', - SELECT_VIEW: 'ui/SELECT_VIEW' + SELECT_VIEW: 'ui/SELECT_VIEW', + TEST_UI: 'ui/SELECT_VIEW' } /* @@ -23,3 +24,4 @@ export const UI = { export const toggleSidebar = createAction(UI.TOGGLE_SIDEBAR); export const setSidebarVisibility = createAction(UI.SET_SIDEBAR_VISIBILITY); export const selectView = createAction(UI.SELECT_VIEW); +export const testUI = ({type:UI.TEST_UI, argu:true}) diff --git a/webui/src/components/Base/Header.js b/webui/src/components/Base/Header.js index 4ce3dc7ce..76c4c4d71 100644 --- a/webui/src/components/Base/Header.js +++ b/webui/src/components/Base/Header.js @@ -42,7 +42,7 @@ const Thumbnail = styled.div` const propTypes = { onSidebarToggle: PropTypes.func.isRequired, - onLogout: PropTypes.func.isRequired + onLogoutRequest: PropTypes.func.isRequired } const Header = ({ onSidebarToggle, onLogoutRequest }) => ( diff --git a/webui/src/containers/Auth.js b/webui/src/containers/Auth.js index 8a7bc852d..b84081493 100644 --- a/webui/src/containers/Auth.js +++ b/webui/src/containers/Auth.js @@ -6,10 +6,6 @@ import Router from 'next/router'; import NProgress from 'nprogress'; import Session from 'services/session'; - -import * as authActions from 'actions/auth'; -import * as uiActions from 'actions/ui'; - import { Login } from 'components'; class Auth extends Component { @@ -61,6 +57,10 @@ class Auth extends Component { password } = this.state.form; + const { + loginRequest + } = this.props; + NProgress.configure({ showSpinner: false }); NProgress.start(); @@ -118,11 +118,4 @@ class Auth extends Component { } } -Auth = connect( - null, - (dispatch) => ({ - UIActions: bindActionCreators(uiActions, dispatch) - }) -)(Auth); - export default Auth; \ No newline at end of file diff --git a/webui/src/reducers/auth.js b/webui/src/reducers/auth.js index 57524ee9d..b8bb09eb3 100644 --- a/webui/src/reducers/auth.js +++ b/webui/src/reducers/auth.js @@ -1,4 +1,3 @@ -import { handleActions } from 'redux-actions'; import { AUTH } from 'actions/auth'; const initialState = { @@ -10,45 +9,47 @@ const initialState = { } } -export default handleActions({ - [AUTH.LOGIN_REQUEST]: (state, action) => ({ - ...state, - isAuthenticating: true, - isAuthenticated: false, - session : { - ...state.session, - username: action.payload.username, - role: '' - } - }), - [AUTH.LOGIN_SUCCESS]: (state, action) => ({ - ...state, - isAuthenticating: false, - isAuthenticated: true, - session : { - ...state.session, - username: action.payload.username, - role: action.payload.role - } - }), - [AUTH.LOGIN_FAILURE]: (state, action) => ({ - ...state, - isAuthenticating: false, - isAuthenticated: false, - session : { - ...state.session, - username: '', - role: '' - } - }), - [AUTH.LOGOUT]: (state, action) => ({ - ...state, - isAuthenticating: false, - isAuthenticated: false, - session : { - ...state.session, - username: '', - role: '' - } - }) -}, initialState); \ No newline at end of file +function auth(state = initialState, action) { + switch (action.type) { + case AUTH.LOGIN_REQUEST: + return { + ...state, + isAuthenticating: true, + isAuthenticated: false, + session : { + ...state.session, + username: action.username, + role: '' + } + } + case AUTH.LOGIN_SUCCESS: + return { + ...state, + isAuthenticating: false, + isAuthenticated: true, + session : { + ...state.session, + username: action.username, + role: action.role + } + } + case AUTH.LOGIN_FAILURE: + return { + ...state, + isAuthenticating: false, + isAuthenticated: false, + session : null + } + case AUTH.LOGOUT: + return { + ...state, + isAuthenticating: false, + isAuthenticated: false, + session : null + } + default: + return state; + } +} + +export default auth; \ No newline at end of file diff --git a/webui/src/sagas/auth.js b/webui/src/sagas/auth.js index 020434371..c85e14bd0 100644 --- a/webui/src/sagas/auth.js +++ b/webui/src/sagas/auth.js @@ -1,8 +1,7 @@ import { take, fork, cancel, call, put } from 'redux-saga/effects'; import Session from 'services/session'; -import { AUTH, loginSucess} from 'actions/auth'; -/* import { UI, toggleSidebar } from 'actions/ui'; */ +import { AUTH, loginSuccess } from 'actions/auth'; function* authorize(username, password) { try { @@ -21,9 +20,8 @@ function* authorize(username, password) { function* loginFlow() { while(true) { - const { payload } = yield take(AUTH.LOGIN_REQUEST); - const { username, password } = payload; - const task = yield fork(authroize, username, password); + const { username, password } = yield take(AUTH.LOGIN_REQUEST); + const task = yield fork(authorize, username, password); const action = yield take([AUTH.LOGOUT, AUTH.LOGIN_FAILURE]); if (action.type === AUTH.LOGOUT) yield cancel(task); @@ -32,18 +30,4 @@ function* loginFlow() { export default function* () { yield loginFlow(); -} - -/* -function* testCode() { - yield put(toggleSidebar()); -} - -function* loginFlow() { - yield takeEvery(UI.SELECT_VIEW, testCode) -} - -export default function* () { - yield loginFlow(); -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/webui/src/services/session.js b/webui/src/services/session.js index bd3d4d99d..245bc4101 100644 --- a/webui/src/services/session.js +++ b/webui/src/services/session.js @@ -143,7 +143,7 @@ export default class Session { // Update local session data this._session = await this.getSession(true) - return resolve(this._session) + return resolve(true) } } xhr.onerror = () => { diff --git a/webui/src/store.js b/webui/src/store.js index db2deb034..29b144633 100644 --- a/webui/src/store.js +++ b/webui/src/store.js @@ -21,4 +21,4 @@ export const initStore = () => { sagaMiddleware.run(rootSaga); return store; -} \ No newline at end of file +}