Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor improvements to disable two-factor authentication
KrzysztofPajakfbb5be7e411e
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xmlindex 7249b0cb2..4469a61f5 100644--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml@@ -702,6 +702,24 @@<Resource Name="account.twofactorauth.disabled"><Value>Two factor authentication disabled</Value></Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.AppVerification.FirstLine">+ <Value>Open authenticator application.</Value>+ </Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.AppVerification.SecondLine">+ <Value>Enter the 6 digit code that authenticator application generates</Value>+ </Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.EmailVerification.FirstLine">+ <Value>Open email from our store - Email Verification Code.</Value>+ </Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.EmailVerification.SecondLine">+ <Value>Enter the 6 digit code that you can find in our message </Value>+ </Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.SMSVerification.FirstLine">+ <Value>Open SMS message from our store - Verification Code.</Value>+ </Resource>+ <Resource Name="Account.TwoFactorAuth.Disable.SMSVerification.SecondLine">+ <Value>Enter the 6 digit code that you can find in our message</Value>+ </Resource><Resource Name="Account.TwoFactorAuth.EmailVerification.FirstLine"><Value>1. Please check your email box</Value></Resource>diff --git a/src/Web/Grand.Web/Controllers/AccountController.cs b/src/Web/Grand.Web/Controllers/AccountController.csindex 668729bc6..e45ed47db 100644--- a/src/Web/Grand.Web/Controllers/AccountController.cs+++ b/src/Web/Grand.Web/Controllers/AccountController.cs@@ -9,15 +9,14 @@ using Grand.Business.Customers.Queries.Models;using Grand.Business.Customers.Utilities;using Grand.Business.Messages.Interfaces;using Grand.Business.System.Interfaces.ExportImport;-using Grand.Web.Common.Controllers;-using Grand.Web.Common.Filters;-using Grand.Web.Common.Security.Captcha;using Grand.Domain.Common;using Grand.Domain.Customers;using Grand.Domain.Stores;using Grand.Infrastructure;using Grand.Infrastructure.Extensions;using Grand.Web.Commands.Models.Customers;+using Grand.Web.Common.Filters;+using Grand.Web.Common.Security.Captcha;using Grand.Web.Extensions;using Grand.Web.Features.Models.Common;using Grand.Web.Features.Models.Customers;@@ -181,8 +180,7 @@ namespace Grand.Web.Controllersif (_customerSettings.TwoFactorAuthenticationType != TwoFactorAuthenticationType.AppVerification){- await _mediator.Send(new GetTwoFactorAuthentication()- {+ await _mediator.Send(new GetTwoFactorAuthentication() {Customer = customer,Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,@@ -394,8 +392,7 @@ namespace Grand.Web.Controllersreturn RedirectToRoute("HomePage");}- var model = await _mediator.Send(new GetRegister()- {+ var model = await _mediator.Send(new GetRegister() {Customer = _workContext.CurrentCustomer,ExcludeProperties = false,Language = _workContext.WorkingLanguage,@@ -451,8 +448,7 @@ namespace Grand.Web.Controllersvar registrationResult = await _customerManagerService.RegisterCustomer(registrationRequest);if (registrationResult.Success){- await _mediator.Send(new CustomerRegisteredCommand()- {+ await _mediator.Send(new CustomerRegisteredCommand() {Customer = _workContext.CurrentCustomer,CustomerAttributes = customerAttributes,Form = form,@@ -507,8 +503,7 @@ namespace Grand.Web.Controllers}//If we got this far, something failed, redisplay form- model = await _mediator.Send(new GetRegister()- {+ model = await _mediator.Send(new GetRegister() {Customer = _workContext.CurrentCustomer,ExcludeProperties = true,Language = _workContext.WorkingLanguage,@@ -541,8 +536,7 @@ namespace Grand.Web.Controllersdefault:break;}- var model = new RegisterResultModel- {+ var model = new RegisterResultModel {Result = resultText};return View(model);@@ -617,8 +611,7 @@ namespace Grand.Web.Controllersif (!await _groupService.IsRegistered(_workContext.CurrentCustomer))return Challenge();- var model = await _mediator.Send(new GetInfo()- {+ var model = await _mediator.Send(new GetInfo() {Customer = _workContext.CurrentCustomer,ExcludeProperties = false,Language = _workContext.WorkingLanguage,@@ -648,8 +641,7 @@ namespace Grand.Web.Controllers{if (ModelState.IsValid && ModelState.ErrorCount == 0){- await _mediator.Send(new UpdateCustomerInfoCommand()- {+ await _mediator.Send(new UpdateCustomerInfoCommand() {Customer = _workContext.CurrentCustomer,CustomerAttributes = customerAttributes,Form = form,@@ -666,8 +658,7 @@ namespace Grand.Web.Controllers}//If we got this far, something failed, redisplay form- model = await _mediator.Send(new GetInfo()- {+ model = await _mediator.Send(new GetInfo() {Model = model,Customer = _workContext.CurrentCustomer,ExcludeProperties = true,@@ -728,8 +719,7 @@ namespace Grand.Web.Controllersif (!await _groupService.IsRegistered(_workContext.CurrentCustomer))return Challenge();- var model = await _mediator.Send(new GetAddressList()- {+ var model = await _mediator.Send(new GetAddressList() {Customer = _workContext.CurrentCustomer,Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore@@ -767,10 +757,8 @@ namespace Grand.Web.Controllersreturn Challenge();var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);- var model = new CustomerAddressEditModel- {- Address = await _mediator.Send(new GetAddressModel()- {+ var model = new CustomerAddressEditModel {+ Address = await _mediator.Send(new GetAddressModel() {Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,Model = null,@@ -814,8 +802,7 @@ namespace Grand.Web.Controllers}var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);//If we got this far, something failed, redisplay form- model.Address = await _mediator.Send(new GetAddressModel()- {+ model.Address = await _mediator.Send(new GetAddressModel() {Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,Model = model.Address,@@ -841,8 +828,7 @@ namespace Grand.Web.Controllersvar countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);var model = new CustomerAddressEditModel();- model.Address = await _mediator.Send(new GetAddressModel()- {+ model.Address = await _mediator.Send(new GetAddressModel() {Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,Model = model.Address,@@ -892,8 +878,7 @@ namespace Grand.Web.Controllers}var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);//If we got this far, something failed, redisplay form- model.Address = await _mediator.Send(new GetAddressModel()- {+ model.Address = await _mediator.Send(new GetAddressModel() {Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,Model = model.Address,@@ -1095,8 +1080,7 @@ namespace Grand.Web.Controllersif (_customerSettings.HideDocumentsTab)return RedirectToRoute("CustomerInfo");- var model = await _mediator.Send(new GetDocuments()- {+ var model = await _mediator.Send(new GetDocuments() {Customer = _workContext.CurrentCustomer,Language = _workContext.WorkingLanguage,Command = command@@ -1137,8 +1121,7 @@ namespace Grand.Web.Controllersif (_workContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))return RedirectToRoute("CustomerInfo");- var model = await _mediator.Send(new GetTwoFactorAuthentication()- {+ var model = await _mediator.Send(new GetTwoFactorAuthentication() {Customer = _workContext.CurrentCustomer,Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,@@ -1192,17 +1175,21 @@ namespace Grand.Web.Controllersif (!_workContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))return RedirectToRoute("CustomerInfo");- var model = await _mediator.Send(new GetTwoFactorAuthentication() {+ _ = await _mediator.Send(new GetTwoFactorAuthentication() {Customer = _workContext.CurrentCustomer,Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,});++ var model = new CustomerInfoModel.TwoFactorAuthorizationModel() {+ TwoFactorAuthenticationType = _customerSettings.TwoFactorAuthenticationType+ };return View(model);}[HttpPost]- public async Task<IActionResult> DisableTwoFactorAuthenticator(CustomerInfoModel.TwoFactorAuthenticationModel model,+ public async Task<IActionResult> DisableTwoFactorAuthenticator(CustomerInfoModel.TwoFactorAuthorizationModel model,[FromServices] ITwoFactorAuthenticationService twoFactorAuthenticationService){if (!await _groupService.IsRegistered(_workContext.CurrentCustomer))@@ -1220,7 +1207,8 @@ namespace Grand.Web.Controllers}else{- if (await twoFactorAuthenticationService.AuthenticateTwoFactor(model.SecretKey, model.Code, _workContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))+ var secretKey = _workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.TwoFactorSecretKey);+ if (await twoFactorAuthenticationService.AuthenticateTwoFactor(secretKey, model.Code, _workContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType)){await _userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.TwoFactorEnabled, false);await _userFieldService.SaveField<string>(_workContext.CurrentCustomer, SystemCustomerFieldNames.TwoFactorSecretKey, null);@@ -1282,8 +1270,7 @@ namespace Grand.Web.Controllersif (!await _groupService.IsOwner(_workContext.CurrentCustomer))return Challenge();- var model = new SubAccountModel()- {+ var model = new SubAccountModel() {Active = true,};return View(model);@@ -1301,8 +1288,7 @@ namespace Grand.Web.Controllersif (ModelState.IsValid){- var result = await _mediator.Send(new SubAccountAddCommand()- {+ var result = await _mediator.Send(new SubAccountAddCommand() {Customer = _workContext.CurrentCustomer,Model = model,Form = form,@@ -1348,8 +1334,7 @@ namespace Grand.Web.Controllersif (ModelState.IsValid){- var result = await _mediator.Send(new SubAccountEditCommand()- {+ var result = await _mediator.Send(new SubAccountEditCommand() {CurrentCustomer = _workContext.CurrentCustomer,Model = model,Form = form,@@ -1382,8 +1367,7 @@ namespace Grand.Web.Controllers//find address (ensure that it belongs to the current customer)if (ModelState.IsValid){- var result = await _mediator.Send(new SubAccountDeleteCommand()- {+ var result = await _mediator.Send(new SubAccountDeleteCommand() {CurrentCustomer = _workContext.CurrentCustomer,CustomerId = id,});diff --git a/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs b/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.csindex 6763d8035..92922c17d 100644--- a/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs+++ b/src/Web/Grand.Web/Models/Customer/CustomerInfoModel.cs@@ -159,7 +159,7 @@ namespace Grand.Web.Models.Customerpublic class TwoFactorAuthorizationModel : BaseModel{public string Code { get; set; }- public string UserName { get; set; }+ public TwoFactorAuthenticationType TwoFactorAuthenticationType { get; set; }}#endregiondiff --git a/src/Web/Grand.Web/Views/Account/DisableTwoFactorAuthenticator.cshtml b/src/Web/Grand.Web/Views/Account/DisableTwoFactorAuthenticator.cshtmlindex d11349827..5021723b4 100644--- a/src/Web/Grand.Web/Views/Account/DisableTwoFactorAuthenticator.cshtml+++ b/src/Web/Grand.Web/Views/Account/DisableTwoFactorAuthenticator.cshtml@@ -1,12 +1,10 @@-@model CustomerInfoModel.TwoFactorAuthenticationModel-@using Grand.Web.Models.Customer;+@model CustomerInfoModel.TwoFactorAuthorizationModel@inject IPageHeadBuilder pagebuilder-@{ Layout = "_TwoColumns";- //title- pagebuilder.AddTitleParts(Loc["Title.TwoFactorAuth"]);- var code = "ManualEntryQrCode";- var imageUrl = "QrCodeImageUrl";- var errors = Model.CustomValues.ContainsKey("Errors") ? Model.CustomValues["Errors"] : null; }+@{+ Layout = "_TwoColumns";+ //title+ pagebuilder.AddTitleParts(Loc["Title.TwoFactorAuth"]);+}@section left{@await Component.InvokeAsync("CustomerNavigation", new { selectedTabId = AccountNavigationEnum.Info })@@ -14,130 +12,42 @@<div class="page login-page"><h2 class="generalTitle">@Loc["Account.TwoFactorAuth.Disable"]</h2>+ <input type="hidden" asp-for="TwoFactorAuthenticationType" /><ul class="pl-0">- <li><b>@Loc[$"Account.TwoFactorAuth.{Model.TwoFactorAuthenticationType}.FirstLine"]</b></li>- <li>@Loc[$"Account.TwoFactorAuth.{Model.TwoFactorAuthenticationType}.SecondLine"]</li>- <li><b>@Loc[$"Account.TwoFactorAuth.{Model.TwoFactorAuthenticationType}.ThirdLine"]</b></li>- <li>@Loc[$"Account.TwoFactorAuth.{Model.TwoFactorAuthenticationType}.FourthLine"]</li>+ <li><b>@Loc[$"Account.TwoFactorAuth.Disable.{Model.TwoFactorAuthenticationType}.FirstLine"]</b></li>+ <li>@Loc[$"Account.TwoFactorAuth.Disable.{Model.TwoFactorAuthenticationType}.SecondLine"]</li></ul>- <div class="message-error">@errors</div>- @if (Model.TwoFactorAuthenticationType == Grand.Domain.Customers.TwoFactorAuthenticationType.AppVerification)- {-@await Component.InvokeAsync("Widget", new { widgetZone = "Enable.TwoFactorAuthentication.AppVerification" })- <div class="mb-2">- <div class="row flex-md-row mt-3 mb-3">- @* login main block *@- <div class="col-lg-6 col-12 text-center">- <div class="card">+ <div asp-validation-summary="ModelOnly" class="message-error alert alert-danger"></div>+ @await Component.InvokeAsync("Widget", new { widgetZone = "Disable.TwoFactorAuthentication.EmailVerification" })+ <div class="mb-2">+ <div class="row flex-md-row mt-3 mb-3">+ <div class="col-lg-6 col-12 text-center">+ <div class="card">+ <form asp-route="DisableEnableTwoFactorAuthorization" method="post">+ <div class="card-body">+ <div class="row justify-content-center">+ <div asp-validation-summary="ModelOnly" class="message-error"></div><div class="col-12 form-group mb-0">- <div>- <img src="@(Model.CustomValues[imageUrl])" />- </div>- <div>- @Loc["Account.TwoFactorAuth.ManualSetupCode"] @(Model.CustomValues[code])- </div>- </div>- <form asp-route="DisableTwoFactorAuthorization" asp-route-returnurl="@Context.Request.Query["ReturnUrl"]" method="post">- <input asp-for="SecretKey" type="hidden" />- <input asp-for="TwoFactorAuthenticationType" type="hidden" />- <input asp-for="@Model.CustomValues[code]" type="hidden" />- <input asp-for="@Model.CustomValues[imageUrl]" type="hidden" />- <div class="card-body">- <div class="row justify-content-center">- <div asp-validation-summary="ModelOnly" class="message-error"></div>- <div class="col-12 form-group mb-0">- <div class="form-group row">- <div class="col-lg-3 col-12">- <label asp-for="Code" class="col-form-label">@Loc["Account.TwoFactorAuth.DigitCode"]</label>- </div>- <div class="col-lg-9 col-12">- <input asp-for="Code" name="Code" type="text" class="form-control" />- <span asp-validation-for="Code"></span>- </div>- </div>- </div>- </div>- </div>- <div class="card-footer">- <div class="buttons">- <input class="btn btn-info login-button" type="submit" value="@Loc["Account.TwoFactorAuth.SendCode"]" />- </div>- </div>- </form>- </div>- </div>- </div>- </div>}- @if (Model.TwoFactorAuthenticationType == Grand.Domain.Customers.TwoFactorAuthenticationType.EmailVerification)- {-@await Component.InvokeAsync("Widget", new { widgetZone = "Enable.TwoFactorAuthentication.EmailVerification" })- <div class="mb-2">- <div class="row flex-md-row mt-3 mb-3">- <div class="col-lg-6 col-12 text-center">- <div class="card">- <form asp-route="DisableEnableTwoFactorAuthorization" asp-route-returnurl="@Context.Request.Query["ReturnUrl"]" method="post">- <input asp-for="SecretKey" type="hidden" />- <input asp-for="TwoFactorAuthenticationType" type="hidden" />- <div class="card-body">- <div class="row justify-content-center">- <div asp-validation-summary="ModelOnly" class="message-error"></div>- <div class="col-12 form-group mb-0">- <div class="form-group row">- <div class="col-lg-3 col-12">- <label asp-for="Code" class="col-form-label">@Loc["Account.TwoFactorAuth.DigitCode"]</label>- </div>- <div class="col-lg-9 col-12">- <input asp-for="Code" name="Code" type="text" class="form-control" />- <span asp-validation-for="Code"></span>- </div>- </div>- </div>+ <div class="form-group row">+ <div class="col-lg-3 col-12">+ <label asp-for="Code" class="col-form-label">@Loc["Account.TwoFactorAuth.DigitCode"]</label></div>- </div>- <div class="card-footer">- <div class="buttons">- <input class="btn btn-info login-button" type="submit" value="@Loc["Account.TwoFactorAuth.SendCode"]" />+ <div class="col-lg-9 col-12">+ <input asp-for="Code" name="Code" type="text" class="form-control" />+ <span asp-validation-for="Code"></span></div></div>- </form>+ </div></div></div>- </div>- </div>}- @if (Model.TwoFactorAuthenticationType == Grand.Domain.Customers.TwoFactorAuthenticationType.SMSVerification && string.IsNullOrWhiteSpace(errors))- {-@await Component.InvokeAsync("Widget", new { widgetZone = "Enable.TwoFactorAuthentication.SMSVerification" })- <div class="mb-2">- <div class="row flex-md-row mt-3 mb-3">- <div class="col-lg-6 col-12 text-center">- <div class="card">- <form asp-route="DisableEnableTwoFactorAuthorization" asp-route-returnurl="@Context.Request.Query["ReturnUrl"]" method="post">- <input asp-for="SecretKey" type="hidden" />- <input asp-for="TwoFactorAuthenticationType" type="hidden" />- <div class="card-body">- <div class="row">- <div asp-validation-summary="ModelOnly" class="message-error"></div>- <div class="col-12 form-group mb-0">- <div class="form-group row">- <div class="col-lg-3 col-12">- <label asp-for="Code" class="col-form-label">@Loc["Account.TwoFactorAuth.DigitCode"]</label>- </div>- <div class="col-lg-9 col-12">- <input asp-for="Code" name="Code" type="text" class="form-control" />- <span asp-validation-for="Code"></span>- </div>- </div>- </div>- </div>- </div>- <div class="card-footer">- <div class="buttons">- <input class="btn btn-info login-button" type="submit" value="@Loc["Account.TwoFactorAuth.SendCode"]" />- </div>- </div>- </form>+ <div class="card-footer">+ <div class="buttons">+ <input class="btn btn-info login-button" type="submit" value="@Loc["Account.TwoFactorAuth.SendCode"]" /></div></div>- </div>- </div>}+ </form>+ </div>+ </div>+ </div>+ </div></div>\ No newline at end of file