Skip to content

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.

Admin panel - The store owner - allow to disable two-factor authentication on the customer

KrzysztofPajak713a081417d1
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.TabInfo.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.TabInfo.cshtml
index d6be4c29b..c25c8012b 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.TabInfo.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/_CreateOrUpdate.TabInfo.cshtml
@@ -77,7 +77,7 @@
</div>
</div>
<div class="form-group">
- @{
+ @{
ViewData["DisableIgnoreAclWarnings"] = true;
}
<admin-label asp-for="CustomerGroups" />
@@ -360,6 +360,16 @@
<span asp-validation-for="FreeShipping"></span>
</div>
</div>
+ <div class="form-group">
+ <admin-label asp-for="TwoFactorEnabled" />
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="TwoFactorEnabled" />
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="TwoFactorEnabled"></span>
+ </div>
+ </div>
@if (!String.IsNullOrEmpty(Model.AffiliateId))
{
<div class="form-group">
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
index b8699cd5d..9a7e119e7 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
@@ -263,6 +263,9 @@ namespace Grand.Web.Admin.Controllers
Error(customerGroupsError, false);
}
+ if (model.TwoFactorEnabled)
+ Warning(_translationService.GetResource("Admin.Customers.Customers.CannotTwoFactorEnabled"));
+
if (ModelState.IsValid)
{
model.Attributes = await ParseCustomCustomerAttributes(form);
@@ -357,6 +360,9 @@ namespace Grand.Web.Admin.Controllers
if (await _groupService.IsSalesManager(_workContext.CurrentCustomer) && customer.Id == _workContext.CurrentCustomer.Id)
ModelState.AddModelError("", "You can't edit own data from admin panel");
+ if(!customer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled) && model.TwoFactorEnabled)
+ Warning(_translationService.GetResource("Admin.Customers.Customers.CannotTwoFactorEnabled"));
+
if (ModelState.IsValid)
{
try
diff --git a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
index 4a5cf9a46..aece454de 100644
--- a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
@@ -137,6 +137,9 @@ namespace Grand.Web.Admin.Models.Customers
[GrandResourceDisplayName("Admin.Customers.Customers.Fields.IsTaxExempt")]
public bool IsTaxExempt { get; set; }
+ [GrandResourceDisplayName("Admin.Customers.Customers.Fields.TwoFactorEnabled")]
+ public bool TwoFactorEnabled { get; set; }
+
[GrandResourceDisplayName("Admin.Customers.Customers.Fields.FreeShipping")]
public bool FreeShipping { get; set; }
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index d24aa2a41..47a14f9b2 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -445,6 +445,7 @@ namespace Grand.Web.Admin.Services
model.AdminComment = customer.AdminComment;
model.IsTaxExempt = customer.IsTaxExempt;
model.FreeShipping = customer.FreeShipping;
+ model.TwoFactorEnabled = customer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled);
model.Active = customer.Active;
model.Owner = await _groupService.IsOwner(customer) ? "" : (await _customerService.GetCustomerById(customer.OwnerId))?.Email;
var result = new StringBuilder();
@@ -807,6 +808,10 @@ namespace Grand.Web.Admin.Services
customer.FreeShipping = model.FreeShipping;
customer.Active = model.Active;
customer.Attributes = model.Attributes;
+
+ if(!model.TwoFactorEnabled)
+ await _userFieldService.SaveField(customer, SystemCustomerFieldNames.TwoFactorEnabled, model.TwoFactorEnabled);
+
//email
if (!string.IsNullOrWhiteSpace(model.Email))
{
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index b36232d8a..085a25cf0 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -6952,6 +6952,9 @@
<Resource Name="Admin.Customers.Customers.CannotBeInVendoGroupWithoutVendorAssociated">
<Value>A customer in the Vendors group should have a vendor account associated.</Value>
</Resource>
+ <Resource Name="Admin.Customers.Customers.CannotTwoFactorEnabled">
+ <Value>You can't enable two-factor authentication (only disable is allowed)</Value>
+ </Resource>
<Resource Name="Admin.Customers.Customers.CurrentShoppingCart">
<Value>Current shopping cart</Value>
</Resource>
@@ -7123,6 +7126,9 @@
<Resource Name="Admin.Customers.Customers.Fields.SystemName">
<Value>System name</Value>
</Resource>
+ <Resource Name="Admin.Customers.Customers.Fields.TwoFactorEnabled">
+ <Value>Two-factor authentication is enabled</Value>
+ </Resource>
<Resource Name="Admin.Customers.Customers.Fields.URLReferrer">
<Value>Created from Url</Value>
</Resource>