internal static RouteValueDictionary GetRedeemedRouteValues(Guid token, EmailConfirmationIntent intent) { switch (intent) { case EmailConfirmationIntent.ResetPassword: return(new RouteValueDictionary(new { area = MVC.Identity.Name, controller = MVC.Identity.ResetPassword.Name, action = MVC.Identity.ResetPassword.ActionNames.Get, token, })); case EmailConfirmationIntent.CreatePassword: return(new RouteValueDictionary(new { area = MVC.Identity.Name, controller = MVC.Identity.CreatePassword.Name, action = MVC.Identity.CreatePassword.ActionNames.Get, token, })); default: throw new NotSupportedException(String.Format( "The email confirmation intent '{0}' is not supported.", intent)); } }
public void SetsResult_ToConfirmEmailRedirect_WhenToken_MatchesUnredeemedEntity() { const string paramName = "some value"; const EmailConfirmationIntent intent = EmailConfirmationIntent.ResetPassword; var confirmation = new EmailConfirmation(intent) { ExpiresOnUtc = DateTime.UtcNow.AddHours(1), }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailConfirmation>()) .Returns(new[] { confirmation }.AsQueryable); var attribute = new ValidateRedeemTicketAttribute(paramName, intent) { Entities = entities.Object, }; var controller = new ConfirmEmailController(null); var filterContext = CreateFilterContext(paramName, confirmation.Token, controller); attribute.OnActionExecuting(filterContext); filterContext.Result.ShouldNotBeNull(); filterContext.Result.ShouldBeType <RedirectToRouteResult>(); var routeResult = (RedirectToRouteResult)filterContext.Result; routeResult.Permanent.ShouldBeFalse(); routeResult.RouteValues["area"].ShouldEqual(MVC.Identity.Name); routeResult.RouteValues["controller"].ShouldEqual(MVC.Identity.ConfirmEmail.Name); routeResult.RouteValues["action"].ShouldEqual(MVC.Identity.ConfirmEmail.ActionNames.Get); routeResult.RouteValues["token"].ShouldEqual(confirmation.Token); }
public void SetsNoResult_WhenTokenMatchesEntity_Unexpired_Redeemed_Unretired_WithCorrectTicketAndIntent() { const string paramName = "some value"; const EmailConfirmationIntent intent = EmailConfirmationIntent.CreatePassword; const string ticket = "ticket value"; var confirmation = new EmailConfirmation(intent) { ExpiresOnUtc = DateTime.UtcNow.AddHours(1), RedeemedOnUtc = DateTime.UtcNow.AddSeconds(-5), Ticket = ticket, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailConfirmation>()) .Returns(new[] { confirmation }.AsQueryable); var attribute = new ValidateRedeemTicketAttribute(paramName, intent) { Entities = entities.Object, }; var controller = new ConfirmEmailController(null); controller.TempData.EmailConfirmationTicket(ticket); var filterContext = CreateFilterContext(paramName, confirmation.Token, controller); attribute.OnActionExecuting(filterContext); filterContext.Result.ShouldBeNull(); controller.TempData.EmailConfirmationTicket().ShouldEqual(ticket); }
public void SetsResult_ToPartialRetiredDenial_WhenToken_MatchesExpiredEntity() { const string paramName = "some value"; const EmailConfirmationIntent intent = EmailConfirmationIntent.CreatePassword; var confirmation = new EmailConfirmation(intent) { ExpiresOnUtc = DateTime.UtcNow.AddHours(1), RetiredOnUtc = DateTime.UtcNow.AddSeconds(-5), }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailConfirmation>()) .Returns(new[] { confirmation }.AsQueryable); var attribute = new ValidateRedeemTicketAttribute(paramName, intent) { Entities = entities.Object, }; var filterContext = CreateFilterContext(paramName, confirmation.Token); attribute.OnActionExecuting(filterContext); filterContext.Result.ShouldNotBeNull(); filterContext.Result.ShouldBeType <PartialViewResult>(); var partialView = (PartialViewResult)filterContext.Result; partialView.ViewName.ShouldEqual(MVC.Identity.ConfirmEmail.Views._denied_all); partialView.Model.ShouldNotBeNull(); partialView.Model.ShouldBeType <ConfirmDeniedModel>(); var model = (ConfirmDeniedModel)partialView.Model; model.Reason.ShouldEqual(ConfirmDeniedBecause.IsRetired); model.Intent.ShouldEqual(confirmation.Intent); }
public void SetsIntentProperty_ToIntentArgValue() { const EmailConfirmationIntent intent = EmailConfirmationIntent.CreatePassword; var attribute = new ValidateRedeemTicketAttribute("paramName", intent); attribute.Intent.ShouldEqual(intent); }
public void ReturnsRouteValues_ForCreatePasswordIntent() { var token = Guid.NewGuid(); const EmailConfirmationIntent intent = EmailConfirmationIntent.CreatePassword; var result = ConfirmEmailController.GetRedeemedRouteValues(token, intent); result.ShouldNotBeNull(); result["area"].ShouldEqual(MVC.Identity.Name); result["controller"].ShouldEqual(MVC.Identity.CreatePassword.Name); result["action"].ShouldEqual(MVC.Identity.CreatePassword.ActionNames.Get); result["token"].ShouldEqual(token); }
public void SetsResult_To404_WhenToken_IsEmptyGuid() { const string paramName = "some value"; const EmailConfirmationIntent intent = EmailConfirmationIntent.ResetPassword; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailConfirmation>()) .Returns(new[] { new EmailConfirmation(EmailConfirmationIntent.CreatePassword) }.AsQueryable); var attribute = new ValidateRedeemTicketAttribute(paramName, intent) { Entities = entities.Object, }; var filterContext = CreateFilterContext(paramName, Guid.Empty); attribute.OnActionExecuting(filterContext); filterContext.Result.ShouldNotBeNull(); filterContext.Result.ShouldBeType <HttpNotFoundResult>(); }
internal static RouteValueDictionary GetRedeemedRouteValues(Guid token, EmailConfirmationIntent intent) { switch (intent) { case EmailConfirmationIntent.ResetPassword: return new RouteValueDictionary(new { area = MVC.Identity.Name, controller = MVC.Identity.ResetPassword.Name, action = MVC.Identity.ResetPassword.ActionNames.Get, token, }); case EmailConfirmationIntent.CreatePassword: return new RouteValueDictionary(new { area = MVC.Identity.Name, controller = MVC.Identity.CreatePassword.Name, action = MVC.Identity.CreatePassword.ActionNames.Get, token, }); default: throw new NotSupportedException(String.Format( "The email confirmation intent '{0}' is not supported.", intent)); } }
public static bool IntentIsCorrect(EmailConfirmation confirmation, EmailConfirmationIntent intent) { // return true (valid) if confirmation intent matches return(confirmation != null && confirmation.Intent == intent); }
protected internal EmailConfirmation(EmailConfirmationIntent intent) : this() { Intent = intent; }
public ConfirmDeniedModel(ConfirmDeniedBecause reason, EmailConfirmationIntent intent) { Reason = reason; Intent = intent; }
protected internal EmailConfirmation(EmailConfirmationIntent intent) : this() { Intent = intent; }
public ValidateRedeemTicketAttribute(string paramName, EmailConfirmationIntent intent) : this(paramName) { Intent = intent; }
public static bool IntentIsCorrect(EmailConfirmation confirmation, EmailConfirmationIntent intent) { // return true (valid) if confirmation intent matches return confirmation != null && confirmation.Intent == intent; }
public ValidateRedeemTicketAttribute(string paramName, EmailConfirmationIntent intent) : this(paramName) { Intent = intent; }
public ConfirmDeniedModel(ConfirmDeniedBecause reason, EmailConfirmationIntent intent) { Reason = reason; Intent = intent; }