remove reduant code

This commit is contained in:
Sukchan Lee 2017-07-07 20:59:07 +09:00
parent ca4177635e
commit 10542373b2
5 changed files with 0 additions and 107 deletions

View file

@ -1,15 +0,0 @@
export const AUTH = {
LOGIN_REQUEST: 'auth/LOGIN_REQUEST',
LOGIN_SUCCESS: 'auth/LOGIN_SUCCESS',
LOGIN_FAILURE: 'auth/LOGIN_FAILURE',
LOGOUT: 'auth/LOGOUT'
}
function action(type, payload = {}) {
return {type, ...payload}
}
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)

View file

@ -1,55 +0,0 @@
import { AUTH } from './actions';
const initialState = {
isAuthenticating: false,
isAuthenticated: false,
session : {
username : '',
role: ''
}
}
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;

View file

@ -1,33 +0,0 @@
import { take, fork, cancel, call, put } from 'redux-saga/effects';
import { AUTH, loginSuccess } from './actions';
import Session from 'modules/auth/session';
function* authorize(username, password) {
try {
const session = new Session();
const sessionData = yield call(session.signin, username, password);
const { role } = sessionData.user;
yield put(loginSuccess, username, role);
} catch (error) {
yield put(loginFailure);
} finally {
if (yield cancelled()) {
// .. put special cancellation handling code here
}
}
}
function* loginFlow() {
while(true) {
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);
}
}
export default function* () {
yield loginFlow();
}

View file

@ -1,12 +1,10 @@
import { combineReducers } from 'redux';
import auth from './auth/reducers';
import crud from './crud/reducers';
import sidebar from './sidebar';
import notifications from './notification/reducers';
export default combineReducers({
auth,
crud,
sidebar,
notifications

View file

@ -1,10 +1,8 @@
import { all, fork } from 'redux-saga/effects';
import auth from './auth/sagas';
import crud from './crud/sagas';
export default function* rootSaga() {
yield all([
fork(auth),
fork(crud)
])
}