コード例 #1
0
 public async Task AccountForgotPasswordPostOkDataResetSent()
 {
     this.userManagerMock.Setup(mock => mock.IsEmailConfirmedAsyncWrap(It.IsAny<int>())).Returns(Task.FromResult(true));
     this.accountController.UserManager = this.userManagerMock.Object;
     var model = new ForgotPasswordViewModel { EmailAddress = "*****@*****.**" };
     var result = await this.accountController.ForgotPassword(model);
     result.Should().BeViewResult().WithViewName("~/Features/Account/ForgotPasswordConfirmation.cshtml");
     this.userManagerMock.Verify(m => m.GeneratePasswordResetTokenAsyncWrap(It.IsAny<int>()), Times.Once);
 }
コード例 #2
0
 public async Task AccountForgotPasswordPostWrongEmailStillReturnsPage()
 {
     this.userManagerMock.Setup(mock => mock.IsEmailConfirmedAsyncWrap(It.IsAny<int>())).Returns(Task.FromResult(true)); // really  should not be this, but to test IF in code....
     this.userManagerMock.Setup(mock => mock.FindByNameAsyncWrap(It.IsAny<string>())).Returns(Task.FromResult<WebUser>(null));
     this.accountController.UserManager = this.userManagerMock.Object;
     var model = new ForgotPasswordViewModel { EmailAddress = "*****@*****.**" };
     var result = await this.accountController.ForgotPassword(model);
     result.Should().BeViewResult().WithViewName("~/Features/Account/ForgotPasswordConfirmation.cshtml");
     this.userManagerMock.Verify(m => m.GeneratePasswordResetTokenAsyncWrap(It.IsAny<int>()), Times.Never); 
 }
コード例 #3
0
 public async Task AccountForgotPasswordPostUnconfirmedEmailStillReturnsPage()
 {
     this.userManagerMock.Setup(mock => mock.IsEmailConfirmedAsyncWrap(It.IsAny<int>())).Returns(Task.FromResult(false));
     this.accountController.UserManager = this.userManagerMock.Object;
     var model = new ForgotPasswordViewModel { EmailAddress = "*****@*****.**" };
     var result = await this.accountController.ForgotPassword(model);
     result.Should().BeViewResult().WithViewName("~/Features/Account/ForgotPasswordConfirmation.cshtml");
     this.userManagerMock.Verify(m => m.GeneratePasswordResetTokenAsyncWrap(It.IsAny<int>()), Times.Never);
 }
コード例 #4
0
        public virtual async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(MVC.Account.Views.ForgotPassword, model);
            }

            var user = await this.UserManager.FindByNameAsyncWrap(model.EmailAddress);
            if (user == null || !(await this.UserManager.IsEmailConfirmedAsyncWrap(user.Id)))
            {
                // Don't reveal that the user does not exist or is not confirmed - all are "OK-ish" and "we sent link..."
                return this.View(MVC.Account.Views.ForgotPasswordConfirmation);
            }

            var code = await this.UserManager.GeneratePasswordResetTokenAsyncWrap(user.Id);
            var callbackUrl = this.Url.Action(MVC.Account.ActionNames.ResetPassword, MVC.Account.Name, new { userId = user.Id, code = code }, protocol: this.Request.Url.Scheme);
            await this.UserManager.SendEmailAsyncWrap(user.Id, "Finnish Immigration eService Reset Password request", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
            this.ViewBag.Link = callbackUrl;
            return this.View(MVC.Account.Views.ForgotPasswordConfirmation);
        }