diff --git a/CoreCms.Net.Auth/Policys/ApiResponse.cs b/CoreCms.Net.Auth/Policys/ApiResponse.cs deleted file mode 100644 index 2e84b25d..00000000 --- a/CoreCms.Net.Auth/Policys/ApiResponse.cs +++ /dev/null @@ -1,56 +0,0 @@ -/*********************************************************************** - * Project: CoreCms - * ProjectName: 核心内容管理系统 - * Web: https://www.corecms.net - * Author: 大灰灰 - * Email: jianweie@163.com - * CreateTime: 2021/1/31 21:45:10 - * Description: 暂无 - ***********************************************************************/ - - -using System; -using System.Collections.Generic; -using System.Text; - -namespace CoreCms.Net.Auth.Policys -{ - public class ApiResponse - { - public int Status { get; set; } = 404; - public object Value { get; set; } = "No Found"; - - public ApiResponse(StatusCode apiCode, object msg = null) - { - switch (apiCode) - { - case StatusCode.CODE401: - { - Status = 401; - Value = "很抱歉,您无权访问该接口,请确保已经登录!"; - } - break; - case StatusCode.CODE403: - { - Status = 403; - Value = "很抱歉,您的访问权限等级不够,联系管理员!"; - } - break; - case StatusCode.CODE500: - { - Status = 500; - Value = msg; - } - break; - } - } - } - - public enum StatusCode - { - CODE401, - CODE403, - CODE404, - CODE500 - } -} diff --git a/CoreCms.Net.Auth/Policys/ApiResponseForClientHandler.cs b/CoreCms.Net.Auth/Policys/ApiResponseForClientHandler.cs index 4c17f6b8..1695198a 100644 --- a/CoreCms.Net.Auth/Policys/ApiResponseForClientHandler.cs +++ b/CoreCms.Net.Auth/Policys/ApiResponseForClientHandler.cs @@ -35,7 +35,7 @@ namespace CoreCms.Net.Auth.Policys protected override async Task HandleChallengeAsync(AuthenticationProperties properties) { Response.ContentType = "application/json"; - //Response.StatusCode = StatusCodes.Status401Unauthorized; + Response.StatusCode = StatusCodes.Status401Unauthorized; //await Response.WriteAsync(JsonConvert.SerializeObject(new ApiResponse(StatusCode.CODE401))); var jm = new WebApiCallBack(); @@ -49,7 +49,7 @@ namespace CoreCms.Net.Auth.Policys protected override async Task HandleForbiddenAsync(AuthenticationProperties properties) { Response.ContentType = "application/json"; - //Response.StatusCode = StatusCodes.Status403Forbidden; + Response.StatusCode = StatusCodes.Status403Forbidden; //await Response.WriteAsync(JsonConvert.SerializeObject(new ApiResponse(StatusCode.CODE403))); var jm = new WebApiCallBack(); diff --git a/CoreCms.Net.Uni-App/CoreShop/common/request/request.js b/CoreCms.Net.Uni-App/CoreShop/common/request/request.js index 63f5879f..ecf6b3b0 100644 --- a/CoreCms.Net.Uni-App/CoreShop/common/request/request.js +++ b/CoreCms.Net.Uni-App/CoreShop/common/request/request.js @@ -35,7 +35,7 @@ module.exports = (vm) => { // }, // 全局自定义验证器。参数为statusCode 且必存在,不用判断空情况。 defaultConfig.validateStatus = (statusCode) => { // statusCode 必存在。此处示例为全局默认配置 - return statusCode >= 200 && statusCode < 300 + return statusCode >= 200 && statusCode < 501 } return defaultConfig @@ -50,11 +50,10 @@ module.exports = (vm) => { // 获取用户token const userToken = db.get("userToken"); if (!userToken) { - console.log("开启弹窗"); + //console.log("开启弹窗"); vm.$store.commit('showLoginTip', true); - console.log("弹窗已经开启"); - - return false; + //console.log("弹窗已经开启"); + //return false; } else { config.header.Authorization = 'Bearer ' + userToken; } @@ -72,39 +71,40 @@ module.exports = (vm) => { // 响应拦截 uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/ + console.log(response); const data = response.data - let pages = getCurrentPages(); - var page = pages[pages.length - 1]; + if (response.statusCode == 200) { + let pages = getCurrentPages(); + var page = pages[pages.length - 1]; - if (!data.status && page) { - //console.log(page.route); - // 登录信息过期或者未登录 - if (data.data === 14007 || data.data === 14006) { - // #ifdef APP-PLUS || APP-PLUS-NVUE - if (page.route.indexOf('pages/login/loginBySMS/loginBySMS') < 0) { + if (!data.status && page) { + // 登录信息过期或者未登录 + if (data.data === 14007 || data.data === 14006) { + // #ifdef APP-PLUS || APP-PLUS-NVUE + if (page.route.indexOf('pages/login/loginBySMS/loginBySMS') < 0) { + db.del("userToken"); + uni.showToast({ + title: result.msg, + icon: 'none', + duration: 1000, + complete: function () { + setTimeout(function () { + uni.hideToast(); + uni.navigateTo({ + url: '/pages/login/loginBySMS/loginBySMS' + }); + }, + 1000); + } + }); + } + // #endif + // #ifdef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO db.del("userToken"); - uni.showToast({ - title: result.msg, - icon: 'none', - duration: 1000, - complete: function () { - setTimeout(function () { - uni.hideToast(); - uni.navigateTo({ - url: '/pages/login/loginBySMS/loginBySMS' - }); - }, - 1000); - } - }); + //console.log("开启登录弹窗"); + vm.$store.commit('hasLogin', false); + // #endif } - // #endif - // #ifdef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO - db.del("userToken"); - console.log("开启登录弹窗"); - //Vue.prototype.$store.commit('showLoginTip', true); - vm.$store.commit('hasLogin', false); - // #endif } } return data === undefined ? {} : data diff --git a/CoreCms.Net.Web.WebApi/Program.cs b/CoreCms.Net.Web.WebApi/Program.cs index bea4432d..37f46677 100644 --- a/CoreCms.Net.Web.WebApi/Program.cs +++ b/CoreCms.Net.Web.WebApi/Program.cs @@ -90,7 +90,7 @@ builder.Services.AddAdminSwaggerSetup(); builder.Services.AddHangFireSetup(); //jwt授权支持注入 -builder.Services.AddAuthorizationSetupForAdmin(); +builder.Services.AddAuthorizationSetupForClient(); //上下文注入 builder.Services.AddHttpContextSetup();