refactor: 重构 SQL 功能到 Tools 控制器下

This commit is contained in:
Argo Zhang 2020-02-22 13:01:04 +08:00
parent dd85f12e79
commit 2c49fbff42
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 50 additions and 36 deletions

View File

@ -1,5 +1,4 @@
using Bootstrap.Client.Models;
using Longbow.Data;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@ -33,41 +32,6 @@ namespace Bootstrap.Client.Controllers
return View(new NavigatorBarModel(this));
}
/// <summary>
/// SQL 视图
/// </summary>
/// <returns></returns>
[Authorize(Roles = "Administrators")]
[HttpGet]
public IActionResult SQL()
{
return View(new SQLModel(this));
}
/// <summary>
/// SQL 视图
/// </summary>
/// <returns></returns>
[HttpPost]
[AutoValidateAntiforgeryToken]
public IActionResult SQL(string sql, string auth)
{
int num;
if (string.IsNullOrEmpty(sql)) num = -2;
else if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(auth, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") != "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=") num = -100;
else num = ExecuteSql(sql);
return View(new SQLModel(this) { Result = num });
}
private int ExecuteSql(string sql)
{
using (var db = DbManager.Create("ba"))
{
return db.Execute(sql);
}
}
/// <summary>
/// 错误视图
/// </summary>

View File

@ -0,0 +1,50 @@
using Bootstrap.Client.Models;
using Longbow.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bootstrap.Client
{
/// <summary>
/// Tools 控制器
/// </summary>
[Authorize]
public class ToolsController : Controller
{
/// <summary>
/// SQL 视图
/// </summary>
/// <returns></returns>
[Authorize(Roles = "Administrators")]
[HttpGet]
public IActionResult SQL()
{
return View(new SQLModel(this));
}
/// <summary>
/// SQL 视图
/// </summary>
/// <returns></returns>
[HttpPost]
[AutoValidateAntiforgeryToken]
public IActionResult SQL(string sql, string auth)
{
int num;
if (string.IsNullOrEmpty(sql)) num = -2;
else if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(auth, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") != "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=") num = -100;
else num = ExecuteSql(sql);
return View(new SQLModel(this) { Result = num });
}
private int ExecuteSql(string sql)
{
using (var db = DbManager.Create("ba"))
{
return db.Execute(sql);
}
}
}
}