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

Merge remote-tracking branch 'origin/master'

parents f7bfe813 08389f5c
......@@ -55,7 +55,7 @@
"Please input your account!":"Please input your email or username!",
"Please-input-your-Password!":"Please input your Password!",
"verify-email":"Verify email",
"verify-email":"Verify Email",
"account-info":"Account Info",
"reset-username":"Reset Username",
"reset-email":"Reset Email",
......
......@@ -241,11 +241,5 @@ export default {
},
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
})
}
}
};
......@@ -75,6 +75,11 @@ export default {
return {
...state, ...action.payload
}
},
getAuthUserSuccess(state, action) {
return {
...state, ...action.payload
}
}
},
effects: {
......@@ -104,33 +109,41 @@ export default {
}
}
},
*preLogin({ payload }, { call, put }) {
const {token } = payload
*getAuthUser({ payload }, { call, put, select }) {
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) {
yield put(routerRedux.replace("/signin"))
}
try {
let { data } = yield call(getAuthUser, { token })
if (data ) {
yield put({ type: 'preLoginSuccess', payload: { user: data, token }})
if(data) {
if (user["id"]) {
if(handleSSO(user)){
return
}
if(data.active) {
if(user.active) {
yield put(routerRedux.replace("/profiles"))
}else {
yield put(routerRedux.replace("/verify"))
}
}
}
} catch (error) {
yield put(routerRedux.replace("/signin"))
message.error(error.message)
}
},
*updateProfile({ payload }, { call, put, select }) {
......@@ -188,14 +201,13 @@ export default {
setup({ dispatch, history }) {
let token = localStorage.getItem("token")
return history.listen(({ pathname, query }) => {
if(pathname == '/' || pathname == 'profiles') {
dispatch({ type: 'preLogin', payload: { token } })
if (token) {
dispatch({type: 'getAuthUser', payload: { token }})
}
if(pathname == 'profiles' && !token) {
history.push("/signin")
history.listen(({ pathname, query }) => {
if(pathname == '/') {
dispatch({ type: 'preLogin'})
}
})
}
......
......@@ -22,7 +22,6 @@ function RouterConfig({ history }) {
return (
<Router history={history}>
<Route path="/" component={Index} >
<Redirect from="/home" to="/profiles" />
<Route path="/signin" component={Login}/>
<Route path="/forgot" component={Forgot}/>
<Route path="/signup" component={Register}/>
......
......@@ -129,7 +129,7 @@ function Index({ dispatch, children, messages }) {
<DocumentTitle title={messages['title'] || 'Moe Cube'} />
<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'}}/>
</Link>
......@@ -139,7 +139,7 @@ function Index({ dispatch, children, messages }) {
defaultSelectedKeys={['1']}
style={{ lineHeight: '64px' }}>
<Menu.Item key="1">
<Link to="/home">
<Link to="/">
Home
</Link>
</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