|
|
@@ -1,6 +1,8 @@
|
|
|
import { routerRedux } from 'dva/router';
|
|
|
+import { stringify } from 'qs';
|
|
|
import { fakeAccountLogin, getFakeCaptcha } from '../services/api';
|
|
|
import { setAuthority } from '../utils/authority';
|
|
|
+import { getPageQuery } from '../utils/utils';
|
|
|
import { reloadAuthorized } from '../utils/Authorized';
|
|
|
|
|
|
export default {
|
|
|
@@ -20,32 +22,45 @@ export default {
|
|
|
// Login successfully
|
|
|
if (response.status === 'ok') {
|
|
|
reloadAuthorized();
|
|
|
- yield put(routerRedux.push('/'));
|
|
|
- }
|
|
|
- },
|
|
|
- *logout(_, { put, select }) {
|
|
|
- try {
|
|
|
- // get location pathname
|
|
|
const urlParams = new URL(window.location.href);
|
|
|
- const pathname = yield select(state => state.routing.location.pathname);
|
|
|
- // add the parameters in the url
|
|
|
- urlParams.searchParams.set('redirect', pathname);
|
|
|
- window.history.replaceState(null, 'login', urlParams.href);
|
|
|
- } finally {
|
|
|
- yield put({
|
|
|
- type: 'changeLoginStatus',
|
|
|
- payload: {
|
|
|
- status: false,
|
|
|
- currentAuthority: 'guest',
|
|
|
- },
|
|
|
- });
|
|
|
- reloadAuthorized();
|
|
|
- yield put(routerRedux.push('/user/login'));
|
|
|
+ const params = getPageQuery();
|
|
|
+ let { redirect } = params;
|
|
|
+ if (redirect) {
|
|
|
+ const redirectUrlParams = new URL(redirect);
|
|
|
+ if (redirectUrlParams.origin === urlParams.origin) {
|
|
|
+ redirect = redirect.substr(urlParams.origin.length);
|
|
|
+ if (redirect.startsWith('/#')) {
|
|
|
+ redirect = redirect.substr(2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ window.location.href = redirect;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yield put(routerRedux.replace(redirect || '/'));
|
|
|
}
|
|
|
},
|
|
|
*getCaptcha({ payload }, { call }) {
|
|
|
yield call(getFakeCaptcha, payload);
|
|
|
},
|
|
|
+ *logout(_, { put }) {
|
|
|
+ yield put({
|
|
|
+ type: 'changeLoginStatus',
|
|
|
+ payload: {
|
|
|
+ status: false,
|
|
|
+ currentAuthority: 'guest',
|
|
|
+ },
|
|
|
+ });
|
|
|
+ reloadAuthorized();
|
|
|
+ yield put(
|
|
|
+ routerRedux.push({
|
|
|
+ pathname: '/user/login',
|
|
|
+ search: stringify({
|
|
|
+ redirect: window.location.href,
|
|
|
+ }),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ },
|
|
|
},
|
|
|
|
|
|
reducers: {
|