refactor: 重构演示模式授权码判断方式

This commit is contained in:
Argo Zhang 2020-03-01 13:06:56 +08:00
parent 7e69d580d1
commit 5f5df6f868
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
5 changed files with 20 additions and 7 deletions

View File

@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost("{id}")]
public bool Post(string id, [FromBody]BootstrapDict dict) => id switch
{
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name, dict.Category),
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name),
"AppPath" => DictHelper.SaveAppSettings(dict),
_ => false
};

View File

@ -244,7 +244,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
/// </summary>
protected async System.Threading.Tasks.Task SaveSystemModel()
{
var ret = DictHelper.UpdateSystemModel(Model.EnableDemo, Model.AuthKey, "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=");
var ret = DictHelper.UpdateSystemModel(Model.EnableDemo, Model.AuthKey);
ShowMessage("保存演示系统设置", ret);
if (ret)
{

View File

@ -144,7 +144,7 @@ $(function () {
var demo = $('#demo').prop('checked') ? "1" : "0";
var authKey = $('#authKey').val();
$.bc({
url: Settings.url + '/Demo', data: { category: "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=", name: authKey, code: demo }, title: '演示系统设置', method: "post",
url: Settings.url + '/Demo', data: { name: authKey, code: demo }, title: '演示系统设置', method: "post",
callback: function (result) {
if (result) {
window.setTimeout(function () { window.location.reload(true); }, 1000);

View File

@ -1,6 +1,7 @@
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow.Cache;
using Longbow.Security.Cryptography;
using Longbow.Web;
using System;
using System.Collections.Generic;
@ -287,18 +288,30 @@ namespace Bootstrap.DataAccess
/// 设置 系统是否为演示系统 默认为 false 不是演示系统
/// </summary>
/// <returns></returns>
public static bool UpdateSystemModel(bool isDemo, string authKey, string result)
public static bool UpdateSystemModel(bool isDemo, string authKey)
{
var ret = false;
// 检查授权码
// 请求者提供 秘钥与结果 服务器端通过算法比对结果
if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(authKey, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") == result)
if (LgbCryptography.ComputeHash(authKey, RetrieveAuthorSalt()) == RetrieveAuthorHash())
{
ret = DbContextManager.Create<Dict>()?.UpdateSystemModel(isDemo) ?? false;
}
return ret;
}
/// <summary>
/// 获得 字典表中配置的授权盐值
/// </summary>
/// <returns></returns>
public static string RetrieveAuthorSalt() => RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "授权盐值")?.Code ?? "";
/// <summary>
/// 获得 字典表中配置的哈希值
/// </summary>
/// <returns></returns>
public static string RetrieveAuthorHash() => RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "哈希结果")?.Code ?? "";
/// <summary>
/// 获得验证码图床地址
/// </summary>

View File

@ -48,10 +48,10 @@ namespace Bootstrap.Admin.Api
public async void Post_Id_Ok()
{
// Demo
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "UnitTest", Code = "0", Category = "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=" });
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "UnitTest", Code = "0" });
Assert.False(resp);
resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "123456", Code = "0", Category = "BPtCMhaFngsDb6NsbnnSgQUn4Ej6PnsvaUV3bChYei8=" });
resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "123789", Code = "0" });
Assert.True(resp);
// AppPath