Commit 618b460f authored by 2breakegg's avatar 2breakegg

Merge remote-tracking branch 'origin/master'

parents f7bfe813 08389f5c
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
"Please input your account!":"Please input your email or username!", "Please input your account!":"Please input your email or username!",
"Please-input-your-Password!":"Please input your Password!", "Please-input-your-Password!":"Please input your Password!",
"verify-email":"Verify email", "verify-email":"Verify Email",
"account-info":"Account Info", "account-info":"Account Info",
"reset-username":"Reset Username", "reset-username":"Reset Username",
"reset-email":"Reset Email", "reset-email":"Reset Email",
......
...@@ -241,11 +241,5 @@ export default { ...@@ -241,11 +241,5 @@ export default {
}, },
}, },
subscriptions: { subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
})
}
} }
}; };
...@@ -75,6 +75,11 @@ export default { ...@@ -75,6 +75,11 @@ export default {
return { return {
...state, ...action.payload ...state, ...action.payload
} }
},
getAuthUserSuccess(state, action) {
return {
...state, ...action.payload
}
} }
}, },
effects: { effects: {
...@@ -104,33 +109,41 @@ export default { ...@@ -104,33 +109,41 @@ export default {
} }
} }
}, },
*preLogin({ payload }, { call, put }) { *getAuthUser({ payload }, { call, put, select }) {
const {token } = payload const { token } = payload
try {
let { data } = yield call(getAuthUser, { token })
if(data) {
yield put({ type: 'getAuthUserSuccess', payload: { user: data, token }})
yield put({ type: 'preLogin'})
}
}catch(error) {
message.error(error.message)
}
},
*preLogin({ payload }, { call, put, select }) {
const {token, user } = yield select(state => state.user)
if(!token) { if(!token) {
yield put(routerRedux.replace("/signin")) yield put(routerRedux.replace("/signin"))
} }
try { try {
let { data } = yield call(getAuthUser, { token }) if (user["id"]) {
if (data ) {
yield put({ type: 'preLoginSuccess', payload: { user: data, token }})
if(data) {
if(handleSSO(user)){ if(handleSSO(user)){
return return
} }
if(data.active) { if(user.active) {
yield put(routerRedux.replace("/profiles")) yield put(routerRedux.replace("/profiles"))
}else { }else {
yield put(routerRedux.replace("/verify")) yield put(routerRedux.replace("/verify"))
} }
}
} }
} catch (error) { } catch (error) {
yield put(routerRedux.replace("/signin")) yield put(routerRedux.replace("/signin"))
message.error(error.message)
} }
}, },
*updateProfile({ payload }, { call, put, select }) { *updateProfile({ payload }, { call, put, select }) {
...@@ -188,14 +201,13 @@ export default { ...@@ -188,14 +201,13 @@ export default {
setup({ dispatch, history }) { setup({ dispatch, history }) {
let token = localStorage.getItem("token") let token = localStorage.getItem("token")
return history.listen(({ pathname, query }) => { if (token) {
dispatch({type: 'getAuthUser', payload: { token }})
if(pathname == '/' || pathname == 'profiles') { }
dispatch({ type: 'preLogin', payload: { token } })
}
if(pathname == 'profiles' && !token) { history.listen(({ pathname, query }) => {
history.push("/signin") if(pathname == '/') {
dispatch({ type: 'preLogin'})
} }
}) })
} }
......
...@@ -22,7 +22,6 @@ function RouterConfig({ history }) { ...@@ -22,7 +22,6 @@ function RouterConfig({ history }) {
return ( return (
<Router history={history}> <Router history={history}>
<Route path="/" component={Index} > <Route path="/" component={Index} >
<Redirect from="/home" to="/profiles" />
<Route path="/signin" component={Login}/> <Route path="/signin" component={Login}/>
<Route path="/forgot" component={Forgot}/> <Route path="/forgot" component={Forgot}/>
<Route path="/signup" component={Register}/> <Route path="/signup" component={Register}/>
......
...@@ -129,7 +129,7 @@ function Index({ dispatch, children, messages }) { ...@@ -129,7 +129,7 @@ function Index({ dispatch, children, messages }) {
<DocumentTitle title={messages['title'] || 'Moe Cube'} /> <DocumentTitle title={messages['title'] || 'Moe Cube'} />
<Header style={{ display: 'flex', alignItems: 'center'}}> <Header style={{ display: 'flex', alignItems: 'center'}}>
<Link to="/home" style={{ marginTop: '20px'}}> <Link to="/" style={{ marginTop: '20px'}}>
<img src={logo} style={{ width: '140px', height: '44px'}}/> <img src={logo} style={{ width: '140px', height: '44px'}}/>
</Link> </Link>
...@@ -139,7 +139,7 @@ function Index({ dispatch, children, messages }) { ...@@ -139,7 +139,7 @@ function Index({ dispatch, children, messages }) {
defaultSelectedKeys={['1']} defaultSelectedKeys={['1']}
style={{ lineHeight: '64px' }}> style={{ lineHeight: '64px' }}>
<Menu.Item key="1"> <Menu.Item key="1">
<Link to="/home"> <Link to="/">
Home Home
</Link> </Link>
</Menu.Item> </Menu.Item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment