From 8a804d654e1407f7ca091d2f9ac44b601fc735c8 Mon Sep 17 00:00:00 2001
From: sin <2943460818@qq.com>
Date: Mon, 4 Mar 2019 11:32:26 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E8=8F=9C=E5=8D=95?=
=?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=20-=20url=20=E6=9D=83?=
=?UTF-8?q?=E9=99=90=E6=8E=A7=E5=88=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin-web/mock/user.js | 32 +++++++++++++++----------------
admin-web/src/models/login.js | 10 +++++++++-
admin-web/src/pages/Authorized.js | 16 +++++++++++-----
admin-web/src/pages/User/Login.js | 10 +++++-----
admin-web/src/services/api.js | 2 +-
5 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/admin-web/mock/user.js b/admin-web/mock/user.js
index 2fb6c60a1..3db39da5f 100644
--- a/admin-web/mock/user.js
+++ b/admin-web/mock/user.js
@@ -1,4 +1,6 @@
// 代码中会兼容本地 service mock 以及部署站点的静态数据
+// import { stringify } from 'qs';
+
export default {
// 支持值为 Object 和 Array
'GET /api/currentUser': {
@@ -72,28 +74,24 @@ export default {
address: 'Sidney No. 1 Lake Park',
},
],
- 'POST /api/login/account': (req, res) => {
- const { password, userName, type } = req.body;
- if (password === 'ant.design' && userName === 'admin') {
+ 'POST /admin-api/admin/passport/login': (req, res) => {
+ const { password, username } = req.body;
+ if (password === 'admin' && username === 'admin') {
res.send({
- status: 'ok',
- type,
- currentAuthority: 'admin',
- });
- return;
- }
- if (password === 'ant.design' && userName === 'user') {
- res.send({
- status: 'ok',
- type,
- currentAuthority: 'user',
+ code: 0,
+ data: {
+ accessToken: '2e3d7635c15e47e997611707a237859f',
+ expiresIn: 2879,
+ refreshToken: 'd091e7c35bbb4313b0f557a6ef23d033',
+ },
+ message: 'string',
});
return;
}
res.send({
- status: 'error',
- type,
- currentAuthority: 'guest',
+ code: 1000,
+ data: {},
+ message: '账号或密码错误!',
});
},
'POST /api/register': (req, res) => {
diff --git a/admin-web/src/models/login.js b/admin-web/src/models/login.js
index 82fc4249a..60b5ef1d3 100644
--- a/admin-web/src/models/login.js
+++ b/admin-web/src/models/login.js
@@ -4,6 +4,7 @@ import { fakeAccountLogin, getFakeCaptcha } from '@/services/api';
import { setAuthority } from '@/utils/authority';
import { getPageQuery } from '@/utils/utils';
import { reloadAuthorized } from '@/utils/Authorized';
+import { setLoginToken } from '../utils/cache';
export default {
namespace: 'login',
@@ -19,8 +20,15 @@ export default {
type: 'changeLoginStatus',
payload: response,
});
+ yield put(routerRedux.replace('/'));
+
// Login successfully
- if (response.status === 'ok') {
+ if (response.code === 0) {
+ // 保存 token 到 localStorage,发送请求的时候,会自动取 token 放到 header
+ setLoginToken(response.data.accessToken, response.data.refreshToken);
+ // 此处直接设置为 admin、和 user 角色,因为暂时不做服务控制前段 角色
+ setAuthority(['admin', 'user']);
+
reloadAuthorized();
const urlParams = new URL(window.location.href);
const params = getPageQuery();
diff --git a/admin-web/src/pages/Authorized.js b/admin-web/src/pages/Authorized.js
index c29d9610e..05d91e45b 100644
--- a/admin-web/src/pages/Authorized.js
+++ b/admin-web/src/pages/Authorized.js
@@ -4,10 +4,16 @@ import { getAuthority } from '@/utils/authority';
import Redirect from 'umi/redirect';
const Authority = getAuthority();
+
+// TODO RenderAuthorized 暂时写死为 admin,次组件集成于 antd-pro 后期有时间处理,(可能有用,可能没用)
+// TODO 可大致分为两种角色,admin 管理员角色,user 代表其他非授权页面,可以公开的
+// const Authorized = RenderAuthorized(['admin', 'user']);
const Authorized = RenderAuthorized(Authority);
-export default ({ children }) => (
- }>
- {children}
-
-);
+export default ({ children }) => {
+ return (
+ }>
+ {children}
+
+ );
+};
diff --git a/admin-web/src/pages/User/Login.js b/admin-web/src/pages/User/Login.js
index 6ddece46d..05875861b 100644
--- a/admin-web/src/pages/User/Login.js
+++ b/admin-web/src/pages/User/Login.js
@@ -24,7 +24,7 @@ class LoginPage extends Component {
onGetCaptcha = () =>
new Promise((resolve, reject) => {
- this.loginForm.validateFields(['mobile'], {}, (err, values) => {
+ this.loginForm.validateFields(['username'], {}, (err, values) => {
if (err) {
reject(err);
} else {
@@ -82,7 +82,7 @@ class LoginPage extends Component {
!submitting &&
this.renderMessage(formatMessage({ id: 'app.login.message-invalid-credentials' }))}