diff --git a/projects/ApiGateway/Gateway.json b/projects/ApiGateway/Gateway.json index 2dbe8806..d16ce537 100644 --- a/projects/ApiGateway/Gateway.json +++ b/projects/ApiGateway/Gateway.json @@ -76,26 +76,6 @@ "HashPattern": null, "MaxRps": 0 }, - { - "Servers": [ - { - "Url": "ws://localhost:8011/", - "Weight": 0, - "MaxRps": 0 - } - ], - "PluginConfig": { - "Requesting": [], - "AgentRequesting": [], - "HeaderWriting": [], - "Requested": [], - "ResponseError": [] - }, - "Url": "ws://localhost/IoTCenter.*", - "Remark": null, - "HashPattern": null, - "MaxRps": 0 - }, { "Servers": [ { diff --git a/projects/UserCenter/Controllers/TokenController.cs b/projects/UserCenter/Controllers/TokenController.cs index 243d8f34..68d63dd9 100644 --- a/projects/UserCenter/Controllers/TokenController.cs +++ b/projects/UserCenter/Controllers/TokenController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using System; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Net.Mime; using System.Security.Claims; @@ -105,7 +106,7 @@ namespace UserCenter.Controllers } [HttpPost] - public ActionResult RefreshToken([FromBody]string refreshToken) + public ActionResult RefreshToken([FromBody][Required]string refreshToken) { try { diff --git a/projects/WebUI/wwwroot/images/empty.png b/projects/WebUI/wwwroot/images/empty.png new file mode 100644 index 00000000..804ec706 Binary files /dev/null and b/projects/WebUI/wwwroot/images/empty.png differ diff --git a/projects/WebUI/wwwroot/pc.js b/projects/WebUI/wwwroot/pc.js index a53c8724..977691c6 100644 --- a/projects/WebUI/wwwroot/pc.js +++ b/projects/WebUI/wwwroot/pc.js @@ -4,7 +4,7 @@ var hubUrl = "/IoTCenter/hub?group=page"; var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).build(); connection.on('Connected', function (id) { connectionId = id; - console.log(connectionId); + console.log('signalR 连接Id:'+connectionId); }); connection.on("ServerToClient", function (method, json, to, from) { console.log(method + ':' + json); @@ -12,33 +12,14 @@ connection.on("ServerToClient", function (method, json, to, from) { function connect() { if (connection.state === signalR.HubConnectionState.Disconnected) { connection.start().then(function () { - console.log('客户端与服务器连接成功!'); + console.log('signalR 连接成功'); }).catch(function (err) { console.log(err); setTimeout(connect, 15 * 1000); }); } } -/// -//var request = function (url, data, success, method) { -// this.url = url; -// this.data = data; -// this.method = method || 'get'; -// this.success = success; -// if (this.method == 'get') { -// axios.get(url, data) -// } -// else { - -// } -// request.then(function (response) { -// this.success(response); -// }).catch(function (error) { -// this.catch(error); -// }).finally(function () { -// this.finally(); -// }); -//} + var token = localStorage.getItem('accessToken'); var refreshToken = localStorage.getItem('refreshToken'); @@ -49,7 +30,7 @@ axios.interceptors.request.use( config.withCredentials = true; config.headers['x-requested-with'] = 'XMLHttpRequest'; config.headers['Authorization'] = 'Bearer ' + token; - console.log(config.headers['Authorization']); + console.log('url:'+config.url + 'auth token:' + config.headers['Authorization']); } } return config; @@ -65,25 +46,25 @@ axios.interceptors.response.use(function (response) { console.log(response); return response; }, function (error) { - console.log('axios.interceptors.response.error:'); + console.log('拦截到返回错误:'); console.log(error.response); - if (error.response.status === 401) { + if (error.response.status === 401 && error.config.url.indexOf('refreshToken')===-1) { var url = '/UserCenter/api/v1/token/refreshToken'; - var data = refreshToken:refreshToken}; - axios.post(url, data) + var data = '"'+refreshToken+'"'; + axios.post(url, data, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) .then(function (response) { token = response.data.accessToken; localStorage.setItem("accessToken", token); refreshToken = response.data.refreshToken; localStorage.setItem("refreshToken", refreshToken); config.headers['Authorization'] = 'Bearer ' + token; - console.log('after refresh token,send request again'); + console.log('刷新token后重发api请求'); axios.request(error.config); }) .catch(function (error) { if (error.response.status === 401) { - console.log('refreshToken invalid'); - router.push('/login') + console.log('refreshToken 已过期'); + router.push('/login'); } }); } diff --git a/projects/WebUI/wwwroot/pchome.html b/projects/WebUI/wwwroot/pchome.html index a95d6656..fb71032c 100644 --- a/projects/WebUI/wwwroot/pchome.html +++ b/projects/WebUI/wwwroot/pchome.html @@ -1,10 +1,8 @@ 
-
- +
-
@@ -21,7 +19,18 @@
- +
+
+
+ +
+
+

{{model.nickName}}

+

{{model.userName}}

+
+
+
+
diff --git a/projects/WebUI/wwwroot/pchome.js b/projects/WebUI/wwwroot/pchome.js index 4398fd0e..944a5028 100644 --- a/projects/WebUI/wwwroot/pchome.js +++ b/projects/WebUI/wwwroot/pchome.js @@ -11,15 +11,23 @@ mounted: function () { console.log('mounted:home'); weui.tab('#tab', { defaultIndex: 1 }); - var url = '/UserCenter/api/v1/Token/GetUserInfo'; + var url = '/UserCenter/api/v1/token/getUserInfo'; + var component = this; axios.get(url) .then(function (response) { - + component.model = response.data; }) .catch(function (error) { }) }, methods: { + logout: function () { + token = null; + refreshToken = null; + localStorage.removeItem('accessToken'); + localStorage.removeItem('refreshToken'); + router.push('/login'); + } } }) });