feat: 网站设置增加登录界面配置

This commit is contained in:
Argo Zhang 2020-03-13 22:30:14 +08:00
parent be1c6919be
commit 19206c564a
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
8 changed files with 93 additions and 12 deletions

View File

@ -77,14 +77,24 @@ namespace Bootstrap.Admin.Controllers
/// <param name="view"></param>
/// <returns></returns>
[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);
}
/// <summary>

View File

@ -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<string, string>(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
/// 获得/设置 是否开启健康检查
/// </summary>
public bool EnableHealth { get; set; }
/// <summary>
/// 获得/设置 字典表中登录首页集合
/// </summary>
public IEnumerable<BootstrapDict> Logins { get; set; }
/// <summary>
/// 获得/设置 登录视图名称 默认是 Login
/// </summary>
public KeyValuePair<string, string> LoginView { get; set; }
}
}

View File

@ -33,6 +33,7 @@
<script src="~/js/login.js" asp-append-version="true"></script>
}
<div class="container-fluid">
<input id="imgUrl" type="hidden" value="@Model.ImageLibUrl" />
<div class="login-container">
<section class="login-sidebox">
<div class="login-sidebox-content">
@ -67,11 +68,11 @@
<div class="login-wrap" data-toggle="LgbValidate" data-valid-button="button[type='submit']">
<div id="loginUser" class="form-group">
<input type="text" name="userName" class="form-control" data-toggle="tooltip" placeholder="用户名"
maxlength="16" data-required-msg="请输入用户名" value="" autofocus data-valid="true" />
maxlength="16" data-required-msg="请输入用户名" value="" autofocus data-valid="true" />
</div>
<div id="loginPwd" class="form-group">
<input type="password" name="password" class="form-control" value="" data-toggle="tooltip"
placeholder="密码" maxlength="16" autocomplete="off" data-required-msg="请输入密码" data-valid="true" />
placeholder="密码" maxlength="16" autocomplete="off" data-required-msg="请输入密码" data-valid="true" />
</div>
<div>
<div id="loginMobile" class="form-group d-none">
@ -82,8 +83,8 @@
</div>
</div>
<input type="tel" id="phone" name="phone" class="form-control digits" data-toggle="tooltip"
placeholder="手机号码" minlength="11" maxlength="11" data-required-msg="请输入手机号码" value=""
data-valid="true" />
placeholder="手机号码" minlength="11" maxlength="11" data-required-msg="请输入手机号码" value=""
data-valid="true" />
</div>
</div>
<div id="loginSMS" class="form-group d-none">
@ -94,11 +95,13 @@
</div>
</div>
<input type="number" id="code" name="code" class="form-control digits" data-toggle="tooltip"
disabled value="" placeholder="验证码" maxlength="4" data-required-msg="请输入验证码"
data-valid="true" />
disabled value="" placeholder="验证码" maxlength="4" data-required-msg="请输入验证码"
data-valid="true" />
<div class="input-group-append">
<button type="button" id="btnSendCode" class="btn btn-sms" data-toggle="tooltip"
title="点击发送验证码">发送验证码</button>
title="点击发送验证码">
发送验证码
</button>
</div>
</div>
</div>
@ -114,7 +117,9 @@
</div>
</div>
<button class="btn btn-lg btn-login btn-block" data-oauth="@Model.AllowOAuth" data-toggle="tooltip"
title="不填写密码默认使用 Gitee 认证" type="submit">登 录</button>
title="不填写密码默认使用 Gitee 认证" type="submit">
登 录
</button>
<div class="d-flex justify-content-center">
<a class="forget-password" href="#">已有帐号,忘记密码?</a>
</div>

View File

@ -57,6 +57,27 @@
</div>
</div>
</div>
<div class="card">
<div class="card-header"><label class="control-label" data-toggle="lgbinfo" data-content="通过此功能进行整个网站的登录界面设置">后台管理登录地址设置</label></div>
<div class="card-body">
<div class="form-group">
<div class="form-group text-right">
<div class="btn-group" role="group">
<div class="btn-group" role="group">
<button id="loginView" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" value="@Model.LoginView.Key">@Model.LoginView.Value</button>
<div class="dropdown-menu">
@foreach (var d in Model.Logins)
{
<a href="#" data-val="@d.Code">@d.Name</a>
}
</div>
</div>
<button class="btn btn-secondary" type="button" data-method="saveLoginView">保存</button>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header"><label class="control-label" data-toggle="lgbinfo" data-content="此功能给前台网站拼接后台功能菜单时使用">后台管理地址设置</label></div>
<div class="card-body" data-toggle="LgbValidate" data-valid-button="[data-method='appPath']">

View File

@ -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;
}
});

View File

@ -325,5 +325,17 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <returns></returns>
public bool RetrieveHealth() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "健康检查" && d.Define == 0)?.Code ?? "0") == "1";
/// <summary>
/// 获得字典表登录界面数据
/// </summary>
/// <returns></returns>
public IEnumerable<BootstrapDict> RetrieveLogins() => DictHelper.RetrieveDicts().Where(d => d.Category == "系统首页" && d.Define == 1);
/// <summary>
/// 获得使用中的登录视图名称
/// </summary>
/// <returns></returns>
public string? RetrieveLoginView() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "网站设置" && d.Name == "登录界面" && d.Define == 1)?.Code;
}
}

View File

@ -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
/// <returns></returns>
public static bool RetrieveHealth() => DbContextManager.Create<Dict>()?.RetrieveHealth() ?? true;
/// <summary>
/// 获得登录界面数据
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveLogins() => DbContextManager.Create<Dict>()?.RetrieveLogins() ?? new BootstrapDict[0];
/// <summary>
/// 获得使用中的登录视图名称
/// </summary>
/// <returns></returns>
public static string RetrieveLoginView() => DbContextManager.Create<Dict>()?.RetrieveLoginView() ?? "Login";
/// <summary>
/// 保存前台应用配置信息
/// </summary>

View File

@ -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);