From 0ef57d819c41b2195a29850a13ec061a97ac29c9 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Sep 2017 13:31:43 +1000 Subject: [PATCH] removes uneeded null checks from AuthenticationController for raising UserManager events --- .../Editors/AuthenticationController.cs | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 2b6b3d8363..c65f11be8d 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -139,9 +139,7 @@ namespace Umbraco.Web.Editors //get the user var user = Security.GetBackOfficeUser(loginModel.Username); - - if (UserManager != null) - UserManager.RaiseLoginSuccessEvent(user.Id); + UserManager.RaiseLoginSuccessEvent(user.Id); return SetPrincipalAndReturnUserDetail(user); case SignInStatus.RequiresVerification: @@ -177,8 +175,7 @@ namespace Umbraco.Web.Editors userId = attemptedUser.Id }); - if (UserManager != null) - UserManager.RaiseLoginRequiresVerificationEvent(attemptedUser.Id); + UserManager.RaiseLoginRequiresVerificationEvent(attemptedUser.Id); return verifyResponse; @@ -225,10 +222,9 @@ namespace Umbraco.Web.Editors Services.TextService.Localize("login/resetPasswordEmailCopySubject", //Ensure the culture of the found user is used for the email! UserExtensions.GetUserCulture(identityUser.Culture, Services.TextService)), - message); - - if(UserManager != null) - UserManager.RaiseForgotPasswordRequestedEvent(user.Id); + message); + + UserManager.RaiseForgotPasswordRequestedEvent(user.Id); } } @@ -295,14 +291,10 @@ namespace Umbraco.Web.Editors switch (result) { case SignInStatus.Success: - if (UserManager != null) - UserManager.RaiseLoginSuccessEvent(user.Id); - + UserManager.RaiseLoginSuccessEvent(user.Id); return SetPrincipalAndReturnUserDetail(user); case SignInStatus.LockedOut: - if (UserManager != null) - UserManager.RaiseAccountLockedEvent(user.Id); - + UserManager.RaiseAccountLockedEvent(user.Id); return Request.CreateValidationErrorResponse("User is locked out"); case SignInStatus.Failure: default: @@ -325,16 +317,16 @@ namespace Umbraco.Web.Editors { Logger.Info( "User {0} is currently locked out, unlocking and resetting AccessFailedCount", - () => model.UserId); + () => model.UserId); //var user = await UserManager.FindByIdAsync(model.UserId); - var unlockResult = await UserManager.SetLockoutEndDateAsync(model.UserId, DateTimeOffset.Now); - if(unlockResult.Succeeded == false) + var unlockResult = await UserManager.SetLockoutEndDateAsync(model.UserId, DateTimeOffset.Now); + if(unlockResult.Succeeded == false) { Logger.Warn("Could not unlock for user {0} - error {1}", - () => model.UserId, () => unlockResult.Errors.First()); - } - + () => model.UserId, () => unlockResult.Errors.First()); + } + var resetAccessFailedCountResult = await UserManager.ResetAccessFailedCountAsync(model.UserId); if (resetAccessFailedCountResult.Succeeded == false) { @@ -342,9 +334,8 @@ namespace Umbraco.Web.Editors () => model.UserId, () => unlockResult.Errors.First()); } } - - if(UserManager != null) - UserManager.RaiseForgotPasswordChangedSuccessEvent(model.UserId); + + UserManager.RaiseForgotPasswordChangedSuccessEvent(model.UserId); return Request.CreateResponse(HttpStatusCode.OK); } return Request.CreateValidationErrorResponse(