Refactor GetBackofficeUserManager calls
This commit is contained in:
@@ -132,9 +132,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
var result = await SignInManager.PasswordSignInAsync(
|
||||
loginModel.Username, loginModel.Password, isPersistent: true, shouldLockout: true);
|
||||
|
||||
var backofficeUserManager = GetBackofficeUserManager();
|
||||
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case SignInStatus.Success:
|
||||
@@ -142,8 +140,8 @@ namespace Umbraco.Web.Editors
|
||||
//get the user
|
||||
var user = Security.GetBackOfficeUser(loginModel.Username);
|
||||
|
||||
if (backofficeUserManager != null)
|
||||
backofficeUserManager.RaiseLoginSuccessEvent(user.Id);
|
||||
if (UserManager != null)
|
||||
UserManager.RaiseLoginSuccessEvent(user.Id);
|
||||
|
||||
return SetPrincipalAndReturnUserDetail(user);
|
||||
case SignInStatus.RequiresVerification:
|
||||
@@ -179,8 +177,8 @@ namespace Umbraco.Web.Editors
|
||||
userId = attemptedUser.Id
|
||||
});
|
||||
|
||||
if (backofficeUserManager != null)
|
||||
backofficeUserManager.RaiseLoginRequiresVerificationEvent(attemptedUser.Id);
|
||||
if (UserManager != null)
|
||||
UserManager.RaiseLoginRequiresVerificationEvent(attemptedUser.Id);
|
||||
|
||||
return verifyResponse;
|
||||
|
||||
@@ -336,28 +334,16 @@ namespace Umbraco.Web.Editors
|
||||
() => User.Identity == null ? "UNKNOWN" : User.Identity.Name,
|
||||
() => TryGetOwinContext().Result.Request.RemoteIpAddress);
|
||||
|
||||
var backofficeUserManager = GetBackofficeUserManager();
|
||||
if (backofficeUserManager != null)
|
||||
if (UserManager != null)
|
||||
{
|
||||
var userId = -1;
|
||||
int.TryParse(User.Identity.GetUserId(), out userId);
|
||||
backofficeUserManager.RaiseLogoutSuccessEvent(userId);
|
||||
UserManager.RaiseLogoutSuccessEvent(userId);
|
||||
}
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
internal BackOfficeUserManager<BackOfficeIdentityUser> GetBackofficeUserManager()
|
||||
{
|
||||
|
||||
if (HttpContext.Current == null) return null;
|
||||
var owinContext = HttpContext.Current.GetOwinContext();
|
||||
if (owinContext == null) return null;
|
||||
var userManager = owinContext.GetBackOfficeUserManager();
|
||||
if (userManager == null) return null;
|
||||
return userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used when the user is auth'd successfully and we need to return an OK with user details along with setting the current Principal in the request
|
||||
/// </summary>
|
||||
|
||||
@@ -666,7 +666,7 @@ namespace Umbraco.Web.Security
|
||||
|
||||
if (membershipProvider.IsUmbracoUsersProvider())
|
||||
{
|
||||
backofficeUserManager = GetBackofficeUserManager();
|
||||
backofficeUserManager = _httpContext.GetOwinContext().GetBackOfficeUserManager();
|
||||
if (backofficeUserManager != null)
|
||||
{
|
||||
var profile = _applicationContext.Services.UserService.GetProfileByUserName(username);
|
||||
@@ -891,15 +891,5 @@ namespace Umbraco.Web.Security
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal BackOfficeUserManager<BackOfficeIdentityUser> GetBackofficeUserManager()
|
||||
{
|
||||
if (HttpContext.Current == null) return null;
|
||||
var owinContext = HttpContext.Current.GetOwinContext();
|
||||
if (owinContext == null) return null;
|
||||
var userManager = owinContext.GetBackOfficeUserManager();
|
||||
if (userManager == null) return null;
|
||||
return userManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,13 +462,9 @@ namespace Umbraco.Web.Security.Providers
|
||||
|
||||
internal BackOfficeUserManager<BackOfficeIdentityUser> GetBackofficeUserManager()
|
||||
{
|
||||
|
||||
if (HttpContext.Current == null) return null;
|
||||
var owinContext = HttpContext.Current.GetOwinContext();
|
||||
if (owinContext == null) return null;
|
||||
var userManager = owinContext.GetBackOfficeUserManager();
|
||||
if (userManager == null) return null;
|
||||
return userManager;
|
||||
return HttpContext.Current == null
|
||||
? null
|
||||
: HttpContext.Current.GetOwinContext().GetBackOfficeUserManager();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user