You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RegisterWithoutUsername view have a bug after form Post, if ModelState have errors, the form throws an exception because after failed register action the error is passed to the view along with the wrong model type
trying to return to RegisterWithoutUsername View with a RegisterViewModel instead of RegisterWithoutUsernameViewModel
To Reproduce
Steps to reproduce the behavior:
appsettings.json should have ResolutionPolicy = Email
go register a new user using an already registered email
Relevant parts of the log file
2020-09-10 15:58:32.348 +02:00 [ERR] Connection ID "17870283323016741994", Request ID "8000046b-0000-f800-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Healox.Authentication.STS.Identity.ViewModels.Account.RegisterViewModel', but this ViewDataDictionary instance requires a model item of type 'Healox.Authentication.STS.Identity.ViewModels.Account.RegisterWithoutUsernameViewModel'.
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(Object value)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary..ctor(ViewDataDictionary source, Object model, Type declaredModelType)
at lambda_method(Closure , ViewDataDictionary )
at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.Activate(Object page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
Steps to Fix
replace the HttpPost Register and the HttpPost RegisterWithoutUsername with the following code
[HttpPost][AllowAnonymous][ValidateAntiForgeryToken]publicasyncTask<IActionResult>Register(RegisterViewModelmodel,stringreturnUrl=null,boolIsCalledFromRegisterWithoutUsername=false){returnUrl=returnUrl??Url.Content("~/");ViewData["ReturnUrl"]=returnUrl;if(!ModelState.IsValid)returnView(model);varuser=newTUser{UserName=model.UserName,Email=model.Email};varresult=await_userManager.CreateAsync(user,model.Password);if(result.Succeeded){varcode=await_userManager.GenerateEmailConfirmationTokenAsync(user);code=WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));varcallbackUrl=Url.Action("ConfirmEmail","Account",new{userId=user.Id,code},HttpContext.Request.Scheme);await_emailSender.SendEmailAsync(model.Email,_localizer["ConfirmEmailTitle"],_localizer["ConfirmEmailBody",HtmlEncoder.Default.Encode(callbackUrl)]);if(_identityOptions.SignIn.RequireConfirmedAccount){returnView("RegisterConfirmation");}else{await_signInManager.SignInAsync(user,isPersistent:false);returnLocalRedirect(returnUrl);}}AddErrors(result);// If we got this far, something failed, redisplay formif(IsCalledFromRegisterWithoutUsername){varregisterWithoutUsernameModel=newRegisterWithoutUsernameViewModel{Email=model.Email,Password=model.Password,ConfirmPassword=model.ConfirmPassword};returnView("RegisterWithoutUsername",registerWithoutUsernameModel);}else{returnView(model);}}[HttpPost][AllowAnonymous][ValidateAntiForgeryToken]publicasyncTask<IActionResult>RegisterWithoutUsername(RegisterWithoutUsernameViewModelmodel,stringreturnUrl=null){varregisterModel=newRegisterViewModel{UserName=model.Email,Email=model.Email,Password=model.Password,ConfirmPassword=model.ConfirmPassword};returnawaitRegister(registerModel,returnUrl,true);}
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
RegisterWithoutUsername view have a bug after form Post, if ModelState have errors, the form throws an exception because after failed register action the error is passed to the view along with the wrong model type
trying to return to RegisterWithoutUsername View with a RegisterViewModel instead of RegisterWithoutUsernameViewModel
To Reproduce
Steps to reproduce the behavior:
appsettings.json should have ResolutionPolicy = Email
go register a new user using an already registered email
Relevant parts of the log file
Steps to Fix
replace the HttpPost Register and the HttpPost RegisterWithoutUsername with the following code
I have a pull request with the fix at Walid-Abdulrazik#1
Have a great day :)
The text was updated successfully, but these errors were encountered: