diff --git a/Admin.IdentityServer/Admin.IdentityServer.csproj b/Admin.IdentityServer/Admin.IdentityServer.csproj index d77bd93..62fa8bf 100644 --- a/Admin.IdentityServer/Admin.IdentityServer.csproj +++ b/Admin.IdentityServer/Admin.IdentityServer.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 xiaoxue 中台Admin统一认证授权服务中心 MIT @@ -9,9 +9,9 @@ https://github.com/zhontai/Admin.IdentityServer git ZhonTai Admin;IdentityServer - 1.3.0.0 - 1.3.0.0 - 1.3.0 + 2.0.0 + 2.0.0 + 2.0.0 36b75d04-04c5-43df-a55b-260f35dae382 @@ -40,25 +40,25 @@ - + - + - + - + - - - - - + + + + + diff --git a/Admin.IdentityServer/Controllers/AccountController.cs b/Admin.IdentityServer/Controllers/AccountController.cs index 1b9e3b2..b3f96c3 100644 --- a/Admin.IdentityServer/Controllers/AccountController.cs +++ b/Admin.IdentityServer/Controllers/AccountController.cs @@ -34,7 +34,7 @@ public class AccountController : Controller private readonly IIdentityServerInteractionService _interaction; private readonly IEventService _events; private readonly AppSettings _appSettings; - //private readonly IHttpClientFactory _httpClientFactory; + private readonly IHttpClientFactory _httpClientFactory; //private readonly IPHelper _iPHelper; public AccountController( @@ -42,8 +42,8 @@ public AccountController( IBaseRepository loginLogRepository, IIdentityServerInteractionService interaction, IEventService events, - AppSettings appSettings - //IHttpClientFactory httpClientFactory, + AppSettings appSettings, + IHttpClientFactory httpClientFactory //IPHelper iPHelper ) { @@ -53,7 +53,7 @@ AppSettings appSettings _interaction = interaction; _events = events; _appSettings = appSettings; - //_httpClientFactory = httpClientFactory; + _httpClientFactory = httpClientFactory; //_iPHelper = iPHelper; } @@ -106,14 +106,22 @@ public async Task Login(LoginInput input) //֤ input.Captcha.DeleteCache = true; - using var client = new HttpClient(); + var client = _httpClientFactory.CreateClient(); var res = await client.GetAsync($"{_appSettings.Captcha.CheckUrl}?{ToParams(input.Captcha)}"); - var content = await res.Content.ReadAsStringAsync(); - var captchaResult = JsonConvert.DeserializeObject>(content); - if (!captchaResult.Success) + if (res.IsSuccessStatusCode) { - return ResponseOutput.NotOk("ȫ֤ͨµ¼"); + var content = await res.Content.ReadAsStringAsync(); + var captchaResult = JsonConvert.DeserializeObject>(content); + if (captchaResult == null || !captchaResult.Success) + { + return ResponseOutput.NotOk("ȫ֤ͨµ¼"); + } + } + else + { + return ResponseOutput.NotOk(res.ReasonPhrase); } + var sw = new Stopwatch(); diff --git a/Admin.IdentityServer/Startup.cs b/Admin.IdentityServer/Startup.cs index 54e7fcf..8466cb7 100644 --- a/Admin.IdentityServer/Startup.cs +++ b/Admin.IdentityServer/Startup.cs @@ -115,6 +115,8 @@ public void ConfigureServices(IServiceCollection services) options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; }); + services.AddHttpClient(); + if (_env.IsDevelopment() || _appSettings.Swagger) { services.AddSwaggerGen(options => diff --git a/Admin.IdentityServer/appsettings.Development.json b/Admin.IdentityServer/appsettings.Development.json index 2acd3b3..d3ad2c6 100644 --- a/Admin.IdentityServer/appsettings.Development.json +++ b/Admin.IdentityServer/appsettings.Development.json @@ -13,5 +13,8 @@ "PostLogoutRedirectUris": [ "http://localhost:9000" ] + }, + "captcha": { + "checkUrl": "http://localhost:8000/api/admin/auth/check-captcha" } } \ No newline at end of file diff --git a/Admin.IdentityServer/appsettings.json b/Admin.IdentityServer/appsettings.json index c3241a6..2b0ab48 100644 --- a/Admin.IdentityServer/appsettings.json +++ b/Admin.IdentityServer/appsettings.json @@ -52,10 +52,9 @@ //SqlServer "Data Source=.;Integrated Security=True;Initial Catalog=admindb;Pooling=true;Min Pool Size=1" //PostgreSQL "Host=localhost;Port=5432;Username=postgres;Password=; Database=admindb;Pooling=true;Minimum Pool Size=1" //Sqlite "Data Source=|DataDirectory|\\admindb.db; Pooling=true;Min Pool Size=1" - "connectionString": "Data Source=D:\\zhontai\\Admin.Core\\Admin.Core\\bin\\Debug\\net5.0\\admindb.db; Pooling=true;Min Pool Size=1" + "connectionString": "Data Source=D:\\zhontai\\Admin.Core\\src\\hosts\\ZhonTai.Host\\bin\\Debug\\net6.0\\admindb.db; Pooling=true;Min Pool Size=1" }, "captcha": { - "checkUrl": "https://admin.zhontai.net/api/Admin/Auth/CheckCaptcha" - //"checkUrl": "http://localhost:8000//api/Admin/Auth/CheckCaptcha" + "checkUrl": "https://admin.zhontai.net/api/admin/auth/check-captcha" } } \ No newline at end of file diff --git a/Admin.IdentityServer/wwwroot/captcha/slide-jigsaw/js/verify.js b/Admin.IdentityServer/wwwroot/captcha/slide-jigsaw/js/verify.js index 686a929..c3e724c 100644 --- a/Admin.IdentityServer/wwwroot/captcha/slide-jigsaw/js/verify.js +++ b/Admin.IdentityServer/wwwroot/captcha/slide-jigsaw/js/verify.js @@ -47,7 +47,7 @@ $.ajax({ type : "get", contentType: "application/json;charset=UTF-8", - url: baseUrl + "/api/Admin/Auth/GetCaptcha", + url: baseUrl + "/api/admin/auth/get-captcha", data :JSON.stringify(data), cache: false, crossDomain: true == !(document.all), @@ -64,7 +64,7 @@ $.ajax({ type : "get", contentType: "application/json;charset=UTF-8", - url: baseUrl + "/api/Admin/Auth/CheckCaptcha", + url: baseUrl + "/api/admin/auth/check-captcha", data: data, cache: false, crossDomain: true == !(document.all), @@ -140,41 +140,14 @@ return false; }); } - - //按下 - this.htmlDoms.move_block.on('touchstart', function(e) { - _this.start(e); - }); - - this.htmlDoms.move_block.on('mousedown', function (e) { - _this.start(e); - }); - - this.htmlDoms.sub_block.on('touchstart', function (e) { - _this.start(e); - }); - this.htmlDoms.sub_block.on('mousedown', function(e) { - _this.start(e); - }); + //按下 + this.htmlDoms.move_block.on('touchstart', _this.start.bind(_this)); + this.htmlDoms.move_block.on('mousedown', _this.start.bind(_this)); - //拖动 - $(document).on("touchmove", function(e) { - _this.move(e); - }); + this.htmlDoms.sub_block.on('touchstart', _this.start.bind(_this)); + this.htmlDoms.sub_block.on('mousedown', _this.start.bind(_this)); - $(document).on("mousemove", function(e) { - _this.move(e); - }); - - //鼠标松开 - $(document).on("touchend", function () { - _this.end(); - }); - $(document).on("mouseup", function() { - _this.end(); - }); - //刷新 _this.$element.find('.verify-refresh').on('click', function () { if (_this.isEnd == false) { @@ -278,9 +251,9 @@ this.startLeft = Math.floor(x - this.htmlDoms.bar_area[0].getBoundingClientRect().left); this.startMoveTime = new Date().getTime(); if (this.isEnd == false) { + var _this = this; if (this.isMobile && this.options.mode == 'hover') { this.htmlDoms.out_panel.show(); - var _this = this; this.$element.off('mousedown.hover').on('mousedown.hover', function (e) { return false; }); @@ -289,7 +262,14 @@ $(document).off('mousedown.hover'); }); } - this.status = true; + this.status = true; + + //拖动 + $(document).on("touchmove", _this.move.bind(_this)); + $(document).on("mousemove", _this.move.bind(_this)); + //鼠标松开 + $(document).on("touchend", _this.end.bind(_this)); + $(document).on("mouseup", _this.end.bind(_this)); } }, @@ -401,6 +381,11 @@ } }) } + //取消事件 + $(document).off("touchmove"); + $(document).off("mousemove"); + $(document).off("touchend"); + $(document).off("mouseup"); }, resetSize : function(obj) { @@ -629,7 +614,6 @@ //加载页面 loadDom : function() { - this.fontPos = []; //选中的坐标信息 this.checkPosArr = []; //用户点击的坐标 this.num = 1; //点击的记数 diff --git a/Admin.IdentityServer/wwwroot/js/is4.js b/Admin.IdentityServer/wwwroot/js/is4.js index c5c9558..ae487fb 100644 --- a/Admin.IdentityServer/wwwroot/js/is4.js +++ b/Admin.IdentityServer/wwwroot/js/is4.js @@ -74,7 +74,8 @@ $(function () { var width = $('.form-group:first').width() + 'px'; // 滑块验证 var slideVerify = $('#content').slideVerify({ - baseUrl: 'https://admin.zhontai.net', //服务器请求地址, 默认地址为Api服务器; + //baseUrl: 'https://admin.zhontai.net', //服务器请求地址, 默认地址为Api服务器; + baseUrl: 'http://localhost:8000', containerId: '#btnLogin',//popup模式 必填 被点击之后出现行为验证码的元素id mode: mode, //展示模式 embed popup imgSize: { //图片的大小对象,有默认值{ width: '310px',height: '155px'},可省略 @@ -100,7 +101,9 @@ $(function () { login(); } }, - error: function () { } //失败的回调 + error: function () { + + } //失败的回调 }); function login() { @@ -113,31 +116,43 @@ $(function () { $me.prop('disabled', true).addClass('is-disabled').text('登录中...'); var input = getInput(); input.captcha = slideVerify.getData() - $.post('/user/login', input, function (res) { - if (!res) { - $me.prop('disabled', false).removeClass('is-disabled').text('重新登录'); - return; - } - if (res.code === 1) { - var returnUrl = $.trim($("#returnUrl").val()); - if (returnUrl) { - window.location.href = returnUrl; + + $.ajax({ + type: "post", + url: '/user/login', + data: input, + cache: false, + success: function (res) { + debugger + if (!res) { + $me.prop('disabled', false).removeClass('is-disabled').text('重新登录'); + return; } - } else { - slideVerify && slideVerify.refresh(); + if (res.code === 1) { + var returnUrl = $.trim($("#returnUrl").val()); + if (returnUrl) { + window.location.href = returnUrl; + } + } else { + slideVerify && slideVerify.refresh(); - $me.prop('disabled', false).removeClass('is-disabled').text('重新登录'); - var msg = res.msg; - if (res.data === 1) { - msg = '您的账号输入不正确,请重新输入'; - $("#userName").focus(); - } else if (res.data === 2) { - msg = '您的密码输入不正确,请重新输入'; - $("#password").focus(); + $me.prop('disabled', false).removeClass('is-disabled').text('重新登录'); + var msg = res.msg; + if (res.data === 1) { + msg = '您的账号输入不正确,请重新输入'; + $("#userName").focus(); + } else if (res.data === 2) { + msg = '您的密码输入不正确,请重新输入'; + $("#password").focus(); + } + showMsg(msg); } - showMsg(msg); + }, + fail: function (err) { + $me.prop('disabled', false).removeClass('is-disabled').text('重新登录'); + showMsg('服务器异常'); } - }); + }) } //登录 diff --git a/Admin.IdentityServer/wwwroot/js/is4.min.js b/Admin.IdentityServer/wwwroot/js/is4.min.js index d8ac69e..4d79cad 100644 --- a/Admin.IdentityServer/wwwroot/js/is4.min.js +++ b/Admin.IdentityServer/wwwroot/js/is4.min.js @@ -1 +1 @@ -$(function(){function s(){return{userName:$.trim($("#userName").val()),password:$.trim($("#password").val()),rememberLogin:!!$("#rememberLogin:checked").val(),returnUrl:$("#returnUrl").val(),__RequestVerificationToken:$("input[name='__RequestVerificationToken']:first").val()}}function u(n){n&&($(".my-alert:first").show().text(n),i&&clearTimeout(i),i=window.setTimeout(function(){$(".my-alert:first").hide().text("")},3e3))}function f(){var r=$("#userName"),i,f;return $.trim(r.val())===""?(r.focus(),$("#lblUserName").show(),!1):(i=$("#password"),$.trim(i.val())==="")?(i.focus(),$("#lblPassword").show(),!1):t!="popup"&&(f=n?n.getData():null,f==null)?(u("请向右拖动滑块填充拼图!"),!1):!0}function e(){var r=f(),t,i;if(!r)return!1;t=$("#btnLogin");t.prop("disabled",!0).addClass("is-disabled").text("登录中...");i=s();i.captcha=n.getData();$.post("/user/login",i,function(i){var f,r;if(!i){t.prop("disabled",!1).removeClass("is-disabled").text("重新登录");return}i.code===1?(f=$.trim($("#returnUrl").val()),f&&(window.location.href=f)):(n&&n.refresh(),t.prop("disabled",!1).removeClass("is-disabled").text("重新登录"),r=i.msg,i.data===1?(r="您的账号输入不正确,请重新输入",$("#userName").focus()):i.data===2&&(r="您的密码输入不正确,请重新输入",$("#password").focus()),u(r))})}var t="popup",i=null,r,n,o;$("#userName").blur(function(){$.trim($(this).val())===""?$("#lblUserName").show():$("#lblUserName").hide()});$("#password").blur(function(){$.trim($(this).val())===""?$("#lblPassword").show():$("#lblPassword").hide()});r=$(".form-group:first").width()+"px";n=$("#content").slideVerify({baseUrl:"https://admin.zhontai.net",containerId:"#btnLogin",mode:t,imgSize:{width:r,height:"155px"},barSize:{width:r,height:"40px"},beforeCheck:function(){var n=f();return n?n:!1},ready:function(){},success:function(){t=="popup"&&e()},error:function(){}});$("#btnLogin").click(function(){return t!="popup"&&e(),!1});o={plat:{userName:"user",password:"111111"},tenant:{userName:"18988889999",password:"111111"}};$(".my-radio-group .my-radio-button__inner").click(function(){$(".my-radio-group .my-radio-button__inner.active").removeClass("active");$(this).addClass("active");var t=$(this).data("value"),n=o[t];n&&($("#userName").val(n.userName),$("#password").val(n.password))})}); \ No newline at end of file +$(function(){function s(){return{userName:$.trim($("#userName").val()),password:$.trim($("#password").val()),rememberLogin:!!$("#rememberLogin:checked").val(),returnUrl:$("#returnUrl").val(),__RequestVerificationToken:$("input[name='__RequestVerificationToken']:first").val()}}function r(n){n&&($(".my-alert:first").show().text(n),i&&clearTimeout(i),i=window.setTimeout(function(){$(".my-alert:first").hide().text("")},3e3))}function f(){var u=$("#userName"),i,f;return $.trim(u.val())===""?(u.focus(),$("#lblUserName").show(),!1):(i=$("#password"),$.trim(i.val())==="")?(i.focus(),$("#lblPassword").show(),!1):t!="popup"&&(f=n?n.getData():null,f==null)?(r("请向右拖动滑块填充拼图!"),!1):!0}function e(){var u=f(),t,i;if(!u)return!1;t=$("#btnLogin");t.prop("disabled",!0).addClass("is-disabled").text("登录中...");i=s();i.captcha=n.getData();$.ajax({type:"post",url:"/user/login",data:i,cache:!1,success:function(i){var f,u;if(!i){t.prop("disabled",!1).removeClass("is-disabled").text("重新登录");return}i.code===1?(f=$.trim($("#returnUrl").val()),f&&(window.location.href=f)):(n&&n.refresh(),t.prop("disabled",!1).removeClass("is-disabled").text("重新登录"),u=i.msg,i.data===1?(u="您的账号输入不正确,请重新输入",$("#userName").focus()):i.data===2&&(u="您的密码输入不正确,请重新输入",$("#password").focus()),r(u))},fail:function(){t.prop("disabled",!1).removeClass("is-disabled").text("重新登录");r("服务器异常")}})}var t="popup",i=null,u,n,o;$("#userName").blur(function(){$.trim($(this).val())===""?$("#lblUserName").show():$("#lblUserName").hide()});$("#password").blur(function(){$.trim($(this).val())===""?$("#lblPassword").show():$("#lblPassword").hide()});u=$(".form-group:first").width()+"px";n=$("#content").slideVerify({baseUrl:"http://localhost:8000",containerId:"#btnLogin",mode:t,imgSize:{width:u,height:"155px"},barSize:{width:u,height:"40px"},beforeCheck:function(){var n=f();return n?n:!1},ready:function(){},success:function(){t=="popup"&&e()},error:function(){}});$("#btnLogin").click(function(){return t!="popup"&&e(),!1});o={plat:{userName:"user",password:"111111"},tenant:{userName:"18988889999",password:"111111"}};$(".my-radio-group .my-radio-button__inner").click(function(){$(".my-radio-group .my-radio-button__inner.active").removeClass("active");$(this).addClass("active");var t=$(this).data("value"),n=o[t];n&&($("#userName").val(n.userName),$("#password").val(n.password))})}); \ No newline at end of file