refactor: 重构 RetrieveUserByUserName 参数
This commit is contained in:
parent
8ec366396a
commit
f781c5ffc2
|
@ -41,7 +41,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
var authenticationType = User.Identity.AuthenticationType;
|
||||
await HttpContext.SignOutAsync();
|
||||
var urlReferrer = Request.Headers["Referer"].FirstOrDefault();
|
||||
return View(new LockModel(this)
|
||||
return View(new LockModel(User.Identity.Name)
|
||||
{
|
||||
AuthenticationType = authenticationType,
|
||||
ReturnUrl = WebUtility.UrlEncode(string.IsNullOrEmpty(urlReferrer) ? CookieAuthenticationDefaults.LoginPath.Value : urlReferrer)
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
[HttpPost]
|
||||
public BootstrapUser RetrieveUserByUserName([FromBody]string userName)
|
||||
{
|
||||
return UserHelper.RetrieveUserByUserName(new GenericIdentity(userName));
|
||||
return UserHelper.RetrieveUserByUserName(userName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[HttpGet]
|
||||
public bool Get(string userName)
|
||||
{
|
||||
return UserHelper.RetrieveUserByUserName(new GenericIdentity(userName)) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName);
|
||||
return UserHelper.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[HttpPut]
|
||||
public bool Put([FromBody]ResetUser user)
|
||||
{
|
||||
if (UserHelper.RetrieveUserByUserName(new GenericIdentity(user.UserName)) == null) return true;
|
||||
if (UserHelper.RetrieveUserByUserName(user.UserName) == null) return true;
|
||||
return UserHelper.ForgotPassword(user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
var model = new HeaderBarModel(User.Identity);
|
||||
var model = new HeaderBarModel(User.Identity.Name);
|
||||
if (string.IsNullOrEmpty(model.UserName)) return Redirect(Request.PathBase + CookieAuthenticationDefaults.LogoutPath);
|
||||
|
||||
var homeUrl = DictHelper.RetrieveHomeUrl(model.AppId);
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace Bootstrap.Admin.HealthChecks
|
|||
try
|
||||
{
|
||||
DbContextManager.Exception = null;
|
||||
var user = UserHelper.RetrieveUserByUserName(new GenericIdentity(userName));
|
||||
var user = UserHelper.RetrieveUserByUserName(userName);
|
||||
displayName = user?.DisplayName;
|
||||
roles = string.Join(",", RoleHelper.RetrievesByUserName(userName) ?? new string[0]);
|
||||
menusCount = MenuHelper.RetrieveMenusByUserName(userName)?.Count() ?? 0;
|
||||
|
|
|
@ -13,10 +13,10 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
/// 默认构造函数
|
||||
/// </summary>
|
||||
/// <param name="identity"></param>
|
||||
public HeaderBarModel(IIdentity identity)
|
||||
/// <param name="userName"></param>
|
||||
public HeaderBarModel(string userName)
|
||||
{
|
||||
var user = UserHelper.RetrieveUserByUserName(identity);
|
||||
var user = UserHelper.RetrieveUserByUserName(userName);
|
||||
if (user != null)
|
||||
{
|
||||
Icon = user.Icon.Contains("://", StringComparison.OrdinalIgnoreCase) ? user.Icon : string.Format("{0}{1}", DictHelper.RetrieveIconFolderPath(), user.Icon);
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="controller"></param>
|
||||
public LockModel(ControllerBase controller) : base(controller.User.Identity)
|
||||
/// <param name="userName"></param>
|
||||
public LockModel(string userName) : base(userName)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Bootstrap.Admin.Models
|
|||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="controller"></param>
|
||||
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity)
|
||||
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity.Name)
|
||||
{
|
||||
Navigations = MenuHelper.RetrieveSystemMenus(UserName, $"~{controller.HttpContext.Request.Path}");
|
||||
var authApps = AppHelper.RetrievesByUserName(controller.User.Identity.Name);
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
public override bool Save(DataAccess.User user)
|
||||
{
|
||||
// 已经存在或者已经在新用户中了
|
||||
if (UserHelper.RetrieveUserByUserName(new GenericIdentity(user.UserName)) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false;
|
||||
if (UserHelper.RetrieveUserByUserName(user.UserName) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false;
|
||||
|
||||
user.PassSalt = LgbCryptography.GenerateSalt();
|
||||
user.Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt);
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
var user = UserHelper.RetrieveUserByUserName(context.User.Identity);
|
||||
var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name);
|
||||
|
||||
// user == null 以前登录过客户端保留了 Cookie 但是用户名可能被系统删除
|
||||
// link bug: https://gitee.com/LongbowEnterprise/BootstrapAdmin/issues/I123MH
|
||||
|
|
|
@ -293,9 +293,9 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 通过登录名获取登录用户方法
|
||||
/// </summary>
|
||||
/// <param name="identity"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static BootstrapUser RetrieveUserByUserName(IIdentity identity) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, identity.Name), k => DbContextManager.Create<User>().RetrieveUserByUserName(identity.Name), RetrieveUsersByNameDataKey);
|
||||
public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbContextManager.Create<User>().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey);
|
||||
|
||||
/// <summary>
|
||||
/// 通过登录账号获得用户信息
|
||||
|
|
|
@ -135,7 +135,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
[Fact]
|
||||
public void RetrieveUserByUserName_Ok()
|
||||
{
|
||||
var usr = UserHelper.RetrieveUserByUserName(new GenericIdentity("Admin"));
|
||||
var usr = UserHelper.RetrieveUserByUserName("Admin");
|
||||
Assert.Equal("Administrator", usr.DisplayName);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue