Skip to content

Commit

Permalink
升级2.0项目
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Apr 17, 2022
1 parent 389fd2a commit 81b715b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 88 deletions.
30 changes: 15 additions & 15 deletions Admin.IdentityServer/Admin.IdentityServer.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Authors>xiaoxue</Authors>
<Description>中台Admin统一认证授权服务中心</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zhontai/Admin.IdentityServer</PackageProjectUrl>
<RepositoryUrl>https://github.com/zhontai/Admin.IdentityServer</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>ZhonTai Admin;IdentityServer</PackageTags>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<Version>1.3.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Version>2.0.0</Version>
<UserSecretsId>36b75d04-04c5-43df-a55b-260f35dae382</UserSecretsId>
</PropertyGroup>

Expand Down Expand Up @@ -40,25 +40,25 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.4" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.4" />
<!--<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.6" />-->
<PackageReference Include="NLog" Version="4.7.11" />
<PackageReference Include="NLog" Version="4.7.15" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
<!--<PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />-->
<PackageReference Include="UAParser" Version="3.1.47" />

<PackageReference Include="FreeSql" Version="2.6.100" />
<PackageReference Include="FreeSql.Repository" Version="2.6.100" />
<!--<PackageReference Include="FreeSql.Provider.MySql" Version="2.6.100" />-->
<!--<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="2.6.100" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="2.6.100" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="2.6.100" />-->
<PackageReference Include="FreeSql.Provider.Sqlite" Version="2.6.100" />
<PackageReference Include="FreeSql" Version="3.2.500" />
<PackageReference Include="FreeSql.Repository" Version="3.2.500" />
<!--<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.500" />-->
<!--<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.500" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.500" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.500" />-->
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.500" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.12" />
</ItemGroup>

Expand Down
26 changes: 17 additions & 9 deletions Admin.IdentityServer/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ 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(
IBaseRepository<UserEntity> userRepository,
IBaseRepository<LoginLogEntity> loginLogRepository,
IIdentityServerInteractionService interaction,
IEventService events,
AppSettings appSettings
//IHttpClientFactory httpClientFactory,
AppSettings appSettings,
IHttpClientFactory httpClientFactory
//IPHelper iPHelper
)
{
Expand All @@ -53,7 +53,7 @@ AppSettings appSettings
_interaction = interaction;
_events = events;
_appSettings = appSettings;
//_httpClientFactory = httpClientFactory;
_httpClientFactory = httpClientFactory;
//_iPHelper = iPHelper;
}

Expand Down Expand Up @@ -106,14 +106,22 @@ public async Task<IResponseOutput> 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<ResultModel<string>>(content);
if (!captchaResult.Success)
if (res.IsSuccessStatusCode)
{
return ResponseOutput.NotOk("安全验证不通过,请重新登录!");
var content = await res.Content.ReadAsStringAsync();
var captchaResult = JsonConvert.DeserializeObject<ResultModel<string>>(content);
if (captchaResult == null || !captchaResult.Success)
{
return ResponseOutput.NotOk("安全验证不通过,请重新登录!");
}
}
else
{
return ResponseOutput.NotOk(res.ReasonPhrase);
}



var sw = new Stopwatch();
Expand Down
2 changes: 2 additions & 0 deletions Admin.IdentityServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
3 changes: 3 additions & 0 deletions Admin.IdentityServer/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"PostLogoutRedirectUris": [
"http://localhost:9000"
]
},
"captcha": {
"checkUrl": "http://localhost:8000/api/admin/auth/check-captcha"
}
}
5 changes: 2 additions & 3 deletions Admin.IdentityServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
58 changes: 21 additions & 37 deletions Admin.IdentityServer/wwwroot/captcha/slide-jigsaw/js/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand 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),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
});
Expand All @@ -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));
}
},

Expand Down Expand Up @@ -401,6 +381,11 @@
}
})
}
//取消事件
$(document).off("touchmove");
$(document).off("mousemove");
$(document).off("touchend");
$(document).off("mouseup");
},

resetSize : function(obj) {
Expand Down Expand Up @@ -629,7 +614,6 @@

//加载页面
loadDom : function() {

this.fontPos = []; //选中的坐标信息
this.checkPosArr = []; //用户点击的坐标
this.num = 1; //点击的记数
Expand Down
61 changes: 38 additions & 23 deletions Admin.IdentityServer/wwwroot/js/is4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},可省略
Expand All @@ -100,7 +101,9 @@ $(function () {
login();
}
},
error: function () { } //失败的回调
error: function () {

} //失败的回调
});

function login() {
Expand All @@ -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('服务器异常');
}
});
})
}

//登录
Expand Down
2 changes: 1 addition & 1 deletion Admin.IdentityServer/wwwroot/js/is4.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 81b715b

Please sign in to comment.