refactor(account): 将密码登录禁用逻辑从控制器移到视图层
- 移除 AccountController 中的密码登录重定向逻辑 - 在 Login.cshtml 视图中添加 DisablePasswordLogin 和 SSO 配置检测 - 根据配置动态显示 SSO 登录或常规登录表单 - 当禁用密码登录时显示 SSO 单点登录按钮 - 移除退出登录时的密码登录禁用判断逻辑
This commit is contained in:
@@ -60,17 +60,8 @@ namespace YLErp.Web.Controllers
|
||||
var strictAuthorize = PS.Config.ErpElement.StrictAuthorize;
|
||||
logger.Info($"[登录页面] 配置检查 - DisablePasswordLogin: {disablePasswordLogin}, StrictAuthorize: {strictAuthorize}, Company: {PS.Config.Company}");
|
||||
|
||||
if (disablePasswordLogin)
|
||||
{
|
||||
var ssoUrl = YLErp.Web.Models.GeneralSSOConfig.AuthUrl;
|
||||
logger.Info($"[登录页面] 密码登录已禁用,准备跳转到SSO: {ssoUrl}");
|
||||
if (!string.IsNullOrEmpty(ssoUrl))
|
||||
{
|
||||
return Redirect(ssoUrl);
|
||||
}
|
||||
logger.Error($"[登录页面] SSO地址未配置,无法跳转");
|
||||
return Content("SSO登录未配置,请联系管理员");
|
||||
}
|
||||
// 注意:DisablePasswordLogin 的逻辑在 Login.cshtml 视图中处理
|
||||
// 这里不再直接跳转,而是显示登录页,由页面决定显示什么内容
|
||||
|
||||
return LoginError(null);
|
||||
}
|
||||
@@ -335,16 +326,6 @@ namespace YLErp.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// 如果禁用了密码登录,显示退出页面(避免循环跳转到SSO)
|
||||
var disablePasswordLogin = PS.Config.ErpElement.DisablePasswordLogin;
|
||||
logger.Info($"[退出登录] 跳转判断 - DisablePasswordLogin: {disablePasswordLogin}, SsoLoginConfig.SSO_Enable: {SsoLoginConfig.SSO_Enable}");
|
||||
|
||||
if (disablePasswordLogin)
|
||||
{
|
||||
logger.Info($"[退出登录] 密码登录已禁用,返回LogOut视图");
|
||||
return View("LogOut");
|
||||
}
|
||||
|
||||
logger.Info($"[退出登录] 跳转到登录页");
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
ViewBag.Title = "登录";
|
||||
var captchaUrl = Url.Action("Captcha") + "?sid=" + Model.SID;
|
||||
Model.LoadTime = DateTime.Now;
|
||||
var disablePasswordLogin = PS.Config?.ErpElement?.DisablePasswordLogin ?? false;
|
||||
var ssoEnable = YLErp.Web.Models.GeneralSSOConfig.Enable;
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -54,51 +56,70 @@
|
||||
</div>
|
||||
<div class="ms-login">
|
||||
<div class="ms-title">@GlobalConfig.ProjectTitle</div>
|
||||
<form id="form1" action="/Account/LoginHandle?g=@(Guid.NewGuid())" method="post" class="ms-content">
|
||||
<input type="hidden" name="SID" value="@(Model.SID)" />
|
||||
<input type="hidden" name="UserName" id="UserName" />
|
||||
<input type="hidden" name="Password" id="Password" />
|
||||
<input type="hidden" name="LoadTime" value="@(Model.LoadTime.ToString("yyyy-MM-dd HH:mm:ss"))" />
|
||||
|
||||
<table class="login-table">
|
||||
<colgroup>
|
||||
<col span="1" width="30" />
|
||||
</colgroup>
|
||||
<tr>
|
||||
<td><img src="~/Images/username.png" /></td>
|
||||
<td><input type="text" class="form-control login-input" id="UserName2" placeholder="用户名" autocomplete="off" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="~/Images/password.png" /></td>
|
||||
<td>
|
||||
<!--阻止chrome浏览器自动填充-->
|
||||
<input type="password" style="display:none" />
|
||||
<input type="password" class="form-control login-input" id="Password2" placeholder="密码" autocomplete="new-password" />
|
||||
</td>
|
||||
</tr>
|
||||
@if (Model.NeedCaptcha)
|
||||
@if (disablePasswordLogin)
|
||||
{
|
||||
<!-- 禁用密码登录,只显示SSO按钮 -->
|
||||
<div class="ms-content" style="text-align: center; padding: 40px 30px;">
|
||||
<p style="color: #fff; margin-bottom: 20px;">请使用SSO单点登录</p>
|
||||
@if (ssoEnable)
|
||||
{
|
||||
<a href="@YLErp.Web.Models.GeneralSSOConfig.AuthUrl" class="btn btn-primary login-btn" style="background-color: #1890ff; border-color: #1890ff;">SSO单点登录</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p style="color: #ff6b6b;">SSO登录未配置,请联系管理员</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<!-- 正常登录表单 -->
|
||||
<form id="form1" action="/Account/LoginHandle?g=@(Guid.NewGuid())" method="post" class="ms-content">
|
||||
<input type="hidden" name="SID" value="@(Model.SID)" />
|
||||
<input type="hidden" name="UserName" id="UserName" />
|
||||
<input type="hidden" name="Password" id="Password" />
|
||||
<input type="hidden" name="LoadTime" value="@(Model.LoadTime.ToString("yyyy-MM-dd HH:mm:ss"))" />
|
||||
|
||||
<table class="login-table">
|
||||
<colgroup>
|
||||
<col span="1" width="30" />
|
||||
</colgroup>
|
||||
<tr>
|
||||
<td><img src="~/Images/username.png" /></td>
|
||||
<td><input type="text" class="form-control login-input" id="UserName2" placeholder="用户名" autocomplete="off" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="~/Images/password.png" /></td>
|
||||
<td>
|
||||
<!--阻止chrome浏览器自动填充-->
|
||||
<input type="password" style="display:none" />
|
||||
<input type="password" class="form-control login-input" id="Password2" placeholder="密码" autocomplete="new-password" />
|
||||
</td>
|
||||
</tr>
|
||||
@if (Model.NeedCaptcha)
|
||||
{
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="text" name="CaptchaCode" id="CaptchaCode" class="form-control login-input mb-2" placeholder="输入验证码" autocomplete="off" />
|
||||
<img onclick="CaptchaClick()" style="cursor:pointer;" id="captcha" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="text" name="CaptchaCode" id="CaptchaCode" class="form-control login-input mb-2" placeholder="输入验证码" autocomplete="off" />
|
||||
<img onclick="CaptchaClick()" style="cursor:pointer;" id="captcha" />
|
||||
<p id="errMsg" style="color:red;">@Html.Raw(Model?.ErrorMessage)</p>
|
||||
<button id="sbumitbtn" type="submit" class="btn btn-primary login-btn">登 录</button>
|
||||
@if (ssoEnable)
|
||||
{
|
||||
<a href="@YLErp.Web.Models.GeneralSSOConfig.AuthUrl" class="btn btn-secondary login-btn" target="_blank">SSO单点登录</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<p id="errMsg" style="color:red;">@Html.Raw(Model?.ErrorMessage)</p>
|
||||
<button id="sbumitbtn" type="submit" class="btn btn-primary login-btn">登 录</button>
|
||||
@if (YLErp.Web.Models.GeneralSSOConfig.Enable)
|
||||
{
|
||||
<a href="@YLErp.Web.Models.GeneralSSOConfig.AuthUrl" class="btn btn-secondary login-btn" target="_blank">SSO单点登录</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</table>
|
||||
</form>
|
||||
}
|
||||
<div style="text-align:center;margin-bottom:1rem">
|
||||
Copyright © 2020 YieldChain All rights reserved.
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user