Refactor GetBackofficeUserManager calls

This commit is contained in:
Sebastiaan Janssen
2017-04-29 22:21:42 +02:00
parent cdab89062e
commit 33d09b14be
3 changed files with 11 additions and 39 deletions

View File

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

View File

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

View File

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