From c609caea2ca1cb38ca0e7a71229a1bd4a760391c Mon Sep 17 00:00:00 2001 From: Shishir H Date: Mon, 14 Aug 2017 11:38:45 -0700 Subject: [PATCH] Revert "[Release Prep][2017.08.14] RI of dev to Master" --- .../Authentication/AuthenticationService.cs | 2 +- .../Controllers/UsersController.cs | 17 ++++------------- .../AuthenticationServiceFacts.cs | 2 +- .../Controllers/UsersControllerFacts.cs | 18 ------------------ 4 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/NuGetGallery/Authentication/AuthenticationService.cs b/src/NuGetGallery/Authentication/AuthenticationService.cs index f07a539258..b37e18152a 100644 --- a/src/NuGetGallery/Authentication/AuthenticationService.cs +++ b/src/NuGetGallery/Authentication/AuthenticationService.cs @@ -388,7 +388,7 @@ public virtual async Task GeneratePasswordResetToken(User user, int expirationIn if (!user.Confirmed) { - throw new UserSafeException(Strings.UserIsNotYetConfirmed); + throw new InvalidOperationException(Strings.UserIsNotYetConfirmed); } if (!string.IsNullOrEmpty(user.PasswordResetToken) && !user.PasswordResetTokenExpirationDate.IsInThePast()) diff --git a/src/NuGetGallery/Controllers/UsersController.cs b/src/NuGetGallery/Controllers/UsersController.cs index 42681c6f1b..ef8efd8551 100644 --- a/src/NuGetGallery/Controllers/UsersController.cs +++ b/src/NuGetGallery/Controllers/UsersController.cs @@ -182,22 +182,13 @@ public virtual async Task ForgotPassword(ForgotPasswordViewModel m if (ModelState.IsValid) { - try + var user = await _authService.GeneratePasswordResetToken(model.Email, Constants.PasswordResetTokenExpirationHours * 60); + if (user != null) { - var user = await _authService.GeneratePasswordResetToken(model.Email, Constants.PasswordResetTokenExpirationHours * 60); - if (user != null) - { - return SendPasswordResetEmail(user, forgotPassword: true); - } - - ModelState.AddModelError("Email", Strings.CouldNotFindAnyoneWithThatEmail); + return SendPasswordResetEmail(user, forgotPassword: true); } - catch (Exception e) - { - e.Log(); - ModelState.AddModelError("Email", e.GetUserSafeMessage()); - } + ModelState.AddModelError("Email", Strings.CouldNotFindAnyoneWithThatEmail); } return View(model); diff --git a/tests/NuGetGallery.Facts/Authentication/AuthenticationServiceFacts.cs b/tests/NuGetGallery.Facts/Authentication/AuthenticationServiceFacts.cs index ceb6e553d5..f493353909 100644 --- a/tests/NuGetGallery.Facts/Authentication/AuthenticationServiceFacts.cs +++ b/tests/NuGetGallery.Facts/Authentication/AuthenticationServiceFacts.cs @@ -978,7 +978,7 @@ public async Task ThrowsExceptionIfUserIsNotConfirmed() authService.Entities.Users.Add(user); // Act/Assert - await AssertEx.Throws(() => authService.GeneratePasswordResetToken(user.Username, 1440)); + await AssertEx.Throws(() => authService.GeneratePasswordResetToken(user.Username, 1440)); } [Fact] diff --git a/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs b/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs index 3fb75b30b1..d644d03ba3 100644 --- a/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs +++ b/tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs @@ -282,24 +282,6 @@ public async Task ReturnsSameViewIfTokenGenerationFails() Assert.NotNull(result); Assert.IsNotType(typeof(RedirectResult), result); } - - [Fact] - public async Task ShowsErrorIfUnconfirmedAccount() - { - var user = new User("user") { UnconfirmedEmailAddress = "unique@example.com" }; - var authService = Get(); - authService.Entities.Users.Add(user); - - var controller = GetController(); - - var model = new ForgotPasswordViewModel { Email = user.Username }; - - var result = await controller.ForgotPassword(model) as ViewResult; - - Assert.NotNull(result); - Assert.IsNotType(typeof(RedirectResult), result); - Assert.Equal("You cannot reset your password until you confirm your account.", controller.ModelState["Email"].Errors[0].ErrorMessage); - } } public class TheResetPasswordAction : TestContainer