diff --git a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs index 3a63eeca..3d1888b4 100644 --- a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs @@ -77,14 +77,24 @@ namespace Bootstrap.Admin.Controllers /// /// [HttpGet] - public ActionResult Login([FromQuery]string? appId = null, [FromQuery]string? view = "Login") + public ActionResult Login([FromQuery]string? appId = null, [FromQuery]string view = "") { if (DictHelper.RetrieveSystemModel()) { ViewBag.UserName = "Admin"; ViewBag.Password = "123789"; } - return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : View(view, new LoginModel(appId)); + return User.Identity.IsAuthenticated ? (ActionResult)Redirect("~/Home/Index") : LoginView(view, new LoginModel(appId)); + } + + private ViewResult LoginView(string view, LoginModel model) + { + if (string.IsNullOrEmpty(view)) + { + // retrieve login view from db + view = DictHelper.RetrieveLoginView(); + } + return View(view, model); } /// diff --git a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs index 4d164881..af2123d6 100644 --- a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs +++ b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs @@ -32,6 +32,10 @@ namespace Bootstrap.Admin.Models EnableDemo = DictHelper.RetrieveSystemModel(); AdminPathBase = DictHelper.RetrievePathBase(); EnableHealth = DictHelper.RetrieveHealth(); + Logins = DictHelper.RetrieveLogins(); + var view = DictHelper.RetrieveLoginView(); + var viewName = Logins.FirstOrDefault(d => d.Code == view)?.Name ?? "系统默认"; + LoginView = new KeyValuePair(view, viewName); var dicts = DictHelper.RetrieveDicts(); Apps = DictHelper.RetrieveApps().Where(d => !d.Key.Equals("BA", StringComparison.OrdinalIgnoreCase)).Select(k => @@ -115,5 +119,15 @@ namespace Bootstrap.Admin.Models /// 获得/设置 是否开启健康检查 /// public bool EnableHealth { get; set; } + + /// + /// 获得/设置 字典表中登录首页集合 + /// + public IEnumerable Logins { get; set; } + + /// + /// 获得/设置 登录视图名称 默认是 Login + /// + public KeyValuePair LoginView { get; set; } } } diff --git a/src/admin/Bootstrap.Admin/Views/Account/Login1.cshtml b/src/admin/Bootstrap.Admin/Views/Account/Login-Gitee.cshtml similarity index 93% rename from src/admin/Bootstrap.Admin/Views/Account/Login1.cshtml rename to src/admin/Bootstrap.Admin/Views/Account/Login-Gitee.cshtml index d792b230..15f203af 100644 --- a/src/admin/Bootstrap.Admin/Views/Account/Login1.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Account/Login-Gitee.cshtml @@ -33,6 +33,7 @@ } + @@ -67,11 +68,11 @@ + maxlength="16" data-required-msg="请输入用户名" value="" autofocus data-valid="true" /> + placeholder="密码" maxlength="16" autocomplete="off" data-required-msg="请输入密码" data-valid="true" /> @@ -82,8 +83,8 @@ + placeholder="手机号码" minlength="11" maxlength="11" data-required-msg="请输入手机号码" value="" + data-valid="true" /> @@ -94,11 +95,13 @@ + disabled value="" placeholder="验证码" maxlength="4" data-required-msg="请输入验证码" + data-valid="true" /> 发送验证码 + title="点击发送验证码"> + 发送验证码 + @@ -114,7 +117,9 @@ 登 录 + title="不填写密码默认使用 Gitee 认证" type="submit"> + 登 录 + 已有帐号,忘记密码? diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml index d3548662..1079fed4 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml @@ -57,6 +57,27 @@ + + 后台管理登录地址设置 + + + + + + @Model.LoginView.Value + + @foreach (var d in Model.Logins) + { + @d.Name + } + + + 保存 + + + + + 后台管理地址设置 diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/settings.js b/src/admin/Bootstrap.Admin/wwwroot/js/settings.js index 16dd4b76..f6a9fbd0 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/settings.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/settings.js @@ -238,6 +238,12 @@ $(function () { } }); break; + case 'saveLoginView': + var logView = $('#loginView').val(); + $.bc({ + url: Settings.url, data: [{ name: 'Login', code: logView }], title: '保存登录界面设置', method: "post" + }); + break; } }); diff --git a/src/admin/Bootstrap.DataAccess/Dict.cs b/src/admin/Bootstrap.DataAccess/Dict.cs index c8f836a3..290c731a 100644 --- a/src/admin/Bootstrap.DataAccess/Dict.cs +++ b/src/admin/Bootstrap.DataAccess/Dict.cs @@ -325,5 +325,17 @@ namespace Bootstrap.DataAccess /// /// public bool RetrieveHealth() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "健康检查" && d.Define == 0)?.Code ?? "0") == "1"; + + /// + /// 获得字典表登录界面数据 + /// + /// + public IEnumerable RetrieveLogins() => DictHelper.RetrieveDicts().Where(d => d.Category == "系统首页" && d.Define == 1); + + /// + /// 获得使用中的登录视图名称 + /// + /// + public string? RetrieveLoginView() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "登录界面" && d.Define == 1)?.Code; } } diff --git a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs index 1ce3c93d..b77b21b5 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -165,7 +165,8 @@ namespace Bootstrap.DataAccess ["CookiePeriod"] = "Cookie保留时长", ["IPCachePeriod"] = "IP请求缓存时长", ["AppPath"] = "后台地址", - ["EnableHealth"] = "健康检查" + ["EnableHealth"] = "健康检查", + ["Login"] = "登录界面" }; var ret = SaveSettings(items.Where(i => cache.Any(c => c.Key == i.Name)).Select(i => new BootstrapDict() { @@ -391,6 +392,18 @@ namespace Bootstrap.DataAccess /// public static bool RetrieveHealth() => DbContextManager.Create()?.RetrieveHealth() ?? true; + /// + /// 获得登录界面数据 + /// + /// + public static IEnumerable RetrieveLogins() => DbContextManager.Create()?.RetrieveLogins() ?? new BootstrapDict[0]; + + /// + /// 获得使用中的登录视图名称 + /// + /// + public static string RetrieveLoginView() => DbContextManager.Create()?.RetrieveLoginView() ?? "Login"; + /// /// 保存前台应用配置信息 /// diff --git a/test/UnitTest/Bootstrap.Admin/Controllers/LoginTest.cs b/test/UnitTest/Bootstrap.Admin/Controllers/LoginTest.cs index 680756f2..404e1726 100644 --- a/test/UnitTest/Bootstrap.Admin/Controllers/LoginTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Controllers/LoginTest.cs @@ -53,7 +53,7 @@ namespace Bootstrap.Admin.Controllers [Fact] public async void Login_Fail() { - var r = await client.GetAsync("/Account/Login?AppId=BA&View=Login"); + var r = await client.GetAsync("/Account/Login?AppId=BA"); Assert.True(r.IsSuccessStatusCode); var content = await r.Content.ReadAsStringAsync(); Assert.Contains("登 录", content);