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
Plugin Authentication.Google - change type of project to Microsoft.NET.Sdk.Razor
KrzysztofPajak359fa31fe4a5
diff --git a/src/Plugins/Authentication.Google/Areas/Admin/Controllers/GoogleAuthenticationSettingsController.cs b/src/Plugins/Authentication.Google/Areas/Admin/Controllers/GoogleAuthenticationSettingsController.csnew file mode 100644index 000000000..297579922--- /dev/null+++ b/src/Plugins/Authentication.Google/Areas/Admin/Controllers/GoogleAuthenticationSettingsController.cs@@ -0,0 +1,87 @@+using Authentication.Google.Models;+using Grand.Business.Common.Interfaces.Configuration;+using Grand.Business.Common.Interfaces.Localization;+using Grand.Business.Common.Interfaces.Security;+using Grand.Business.Common.Services.Security;+using Grand.Web.Common.Controllers;+using Grand.Web.Common.Filters;+using Grand.Web.Common.Security.Authorization;+using Microsoft.AspNetCore.Mvc;+using System.Threading.Tasks;++namespace Authentication.Google.Controllers+{+ [AuthorizeAdmin]+ [Area("Admin")]+ [PermissionAuthorize(PermissionSystemName.ExternalAuthenticationMethods)]+ public class GoogleAuthenticationSettingsController : BasePluginController+ {+ #region Fields++ private readonly GoogleExternalAuthSettings _googleExternalAuthSettings;+ private readonly ITranslationService _translationService;+ private readonly IPermissionService _permissionService;+ private readonly ISettingService _settingService;++ #endregion++ #region Ctor++ public GoogleAuthenticationSettingsController(+ GoogleExternalAuthSettings googleExternalAuthSettings,+ ITranslationService translationService,+ IPermissionService permissionService,+ ISettingService settingService)+ {+ _googleExternalAuthSettings = googleExternalAuthSettings;+ _translationService = translationService;+ _permissionService = permissionService;+ _settingService = settingService;+ }++ #endregion++ #region Methods+++ public async Task<IActionResult> Configure()+ {+ if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods))+ return AccessDeniedView();++ var model = new ConfigurationModel {+ ClientKeyIdentifier = _googleExternalAuthSettings.ClientKeyIdentifier,+ ClientSecret = _googleExternalAuthSettings.ClientSecret,+ DisplayOrder = _googleExternalAuthSettings.DisplayOrder+ };++ return View(model);+ }++ [HttpPost]+ public async Task<IActionResult> Configure(ConfigurationModel model)+ {+ if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods))+ return AccessDeniedView();++ if (!ModelState.IsValid)+ return await Configure();++ _googleExternalAuthSettings.ClientKeyIdentifier = model.ClientKeyIdentifier;+ _googleExternalAuthSettings.ClientSecret = model.ClientSecret;+ _googleExternalAuthSettings.DisplayOrder = model.DisplayOrder;++ await _settingService.SaveSetting(_googleExternalAuthSettings);++ //now clear settings cache+ await _settingService.ClearCache();++ Success(_translationService.GetResource("Admin.Plugins.Saved"));++ return await Configure();++ }++ #endregion+ }+}\ No newline at end of filediff --git a/src/Plugins/Authentication.Google/Views/Configure.cshtml b/src/Plugins/Authentication.Google/Areas/Admin/Views/GoogleAuthenticationSettings/Configure.cshtmlsimilarity index 95%rename from src/Plugins/Authentication.Google/Views/Configure.cshtmlrename to src/Plugins/Authentication.Google/Areas/Admin/Views/GoogleAuthenticationSettings/Configure.cshtmlindex 045952c7b..d5779f7d7 100644--- a/src/Plugins/Authentication.Google/Views/Configure.cshtml+++ b/src/Plugins/Authentication.Google/Areas/Admin/Views/GoogleAuthenticationSettings/Configure.cshtml@@ -4,7 +4,7 @@}<input id="active-menu-item" type="hidden" value="/Admin/ExternalAuthentication/Methods" />-<form asp-controller="GoogleAuthentication" asp-action="Configure" method="post">+<form asp-controller="GoogleAuthenticationSettings" asp-area="Admin" asp-action="Configure" method="post"><div class="panel-group"><div class="panel panel-default">diff --git a/src/Plugins/Authentication.Google/Areas/Admin/_ViewImports.cshtml b/src/Plugins/Authentication.Google/Areas/Admin/_ViewImports.cshtmlnew file mode 100644index 000000000..2fb08c043--- /dev/null+++ b/src/Plugins/Authentication.Google/Areas/Admin/_ViewImports.cshtml@@ -0,0 +1,8 @@+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers+@addTagHelper *, Grand.Web.Common+@addTagHelper *, Grand.Web++@using Microsoft.AspNetCore.Mvc.ViewFeatures+@using Grand.Infrastructure.Extensions++@inject Grand.Web.Common.Localization.LocService Locdiff --git a/src/Plugins/Authentication.Google/Authentication.Google.csproj b/src/Plugins/Authentication.Google/Authentication.Google.csprojindex 412ee5975..9567b7e74 100644--- a/src/Plugins/Authentication.Google/Authentication.Google.csproj+++ b/src/Plugins/Authentication.Google/Authentication.Google.csproj@@ -1,4 +1,4 @@-<Project Sdk="Microsoft.NET.Sdk">+<Project Sdk="Microsoft.NET.Sdk.Razor"><PropertyGroup><TargetFramework>net5.0</TargetFramework>@@ -6,6 +6,7 @@<Authors>UNIT-SOFT Sp. z o.o.</Authors><Company>UNIT-SOFT Sp. z o.o.</Company><PackageProjectUrl>https://grandnode.com/</PackageProjectUrl>+ <AddRazorSupportForMvc>true</AddRazorSupportForMvc></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"><OutputPath>..\..\Web\Grand.Web\Plugins\Authentication.Google</OutputPath>@@ -88,18 +89,6 @@<None Update="logo.jpg"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>- <None Update="Views\Configure.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None>- <None Update="Views\PublicInfo.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None>- <None Update="Views\SignInFailed.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None>- <None Update="Views\_ViewImports.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None></ItemGroup></Project>diff --git a/src/Plugins/Authentication.Google/Components/GoogleAuthenticationViewComponent.cs b/src/Plugins/Authentication.Google/Components/GoogleAuthenticationViewComponent.csindex 391988cc9..05f6eb47d 100644--- a/src/Plugins/Authentication.Google/Components/GoogleAuthenticationViewComponent.cs+++ b/src/Plugins/Authentication.Google/Components/GoogleAuthenticationViewComponent.cs@@ -7,7 +7,7 @@ namespace Authentication.Google.Components{public IViewComponentResult Invoke(){- return View("~/Plugins/Authentication.Google/Views/PublicInfo.cshtml");+ return View();}}}\ No newline at end of filediff --git a/src/Plugins/Authentication.Google/Controllers/GoogleAuthenticationController.cs b/src/Plugins/Authentication.Google/Controllers/GoogleAuthenticationController.csindex c54b1a4b3..f99f664cf 100644--- a/src/Plugins/Authentication.Google/Controllers/GoogleAuthenticationController.cs+++ b/src/Plugins/Authentication.Google/Controllers/GoogleAuthenticationController.cs@@ -1,14 +1,8 @@using Authentication.Google.Models;using Grand.Business.Authentication.Interfaces;using Grand.Business.Authentication.Utilities;-using Grand.Business.Common.Interfaces.Configuration;-using Grand.Business.Common.Interfaces.Localization;-using Grand.Business.Common.Interfaces.Security;-using Grand.Business.Common.Services.Security;-using Grand.Web.Common.Controllers;-using Grand.Web.Common.Filters;-using Grand.Infrastructure;using Grand.SharedKernel;+using Grand.Web.Common.Controllers;using Microsoft.AspNetCore.Authentication;using Microsoft.AspNetCore.Authentication.Google;using Microsoft.AspNetCore.Mvc;@@ -22,78 +16,23 @@ namespace Authentication.Google.Controllers{#region Fields- private readonly GoogleExternalAuthSettings _googleExternalAuthSettings;private readonly IExternalAuthenticationService _externalAuthenticationService;- private readonly ITranslationService _translationService;- private readonly IPermissionService _permissionService;- private readonly ISettingService _settingService;-+ private readonly GoogleExternalAuthSettings _googleExternalAuthSettings;#endregion#region Ctor- public GoogleAuthenticationController(GoogleExternalAuthSettings googleExternalAuthSettings,- IExternalAuthenticationService externalAuthenticationService,- ITranslationService translationService,- IPermissionService permissionService,- ISettingService settingService)+ public GoogleAuthenticationController(IExternalAuthenticationService externalAuthenticationService,+ GoogleExternalAuthSettings googleExternalAuthSettings){- _googleExternalAuthSettings = googleExternalAuthSettings;_externalAuthenticationService = externalAuthenticationService;- _translationService = translationService;- _permissionService = permissionService;- _settingService = settingService;+ _googleExternalAuthSettings = googleExternalAuthSettings;}#endregion#region Methods- [AuthorizeAdmin]- [Area("Admin")]- public async Task<IActionResult> Configure()- {- if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods))- return AccessDeniedView();-- var model = new ConfigurationModel- {- ClientKeyIdentifier = _googleExternalAuthSettings.ClientKeyIdentifier,- ClientSecret = _googleExternalAuthSettings.ClientSecret,- DisplayOrder = _googleExternalAuthSettings.DisplayOrder- };-- return View("~/Plugins/Authentication.Google/Views/Configure.cshtml", model);- }-- [HttpPost]- [AutoValidateAntiforgeryToken]- [AuthorizeAdmin]- [Area("Admin")]- public async Task<IActionResult> Configure(ConfigurationModel model)- {- if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods))- return AccessDeniedView();-- if (!ModelState.IsValid)- return await Configure();-- _googleExternalAuthSettings.ClientKeyIdentifier = model.ClientKeyIdentifier;- _googleExternalAuthSettings.ClientSecret = model.ClientSecret;- _googleExternalAuthSettings.DisplayOrder = model.DisplayOrder;-- await _settingService.SaveSetting(_googleExternalAuthSettings);-- //now clear settings cache- await _settingService.ClearCache();-- Success(_translationService.GetResource("Admin.Plugins.Saved"));-- return await Configure();-- }--public IActionResult GoogleLogin(string returnUrl){if (!_externalAuthenticationService.AuthenticationProviderIsAvailable(GoogleAuthenticationDefaults.ProviderSystemName))@@ -103,8 +42,7 @@ namespace Authentication.Google.Controllersthrow new GrandException("Google authentication module not configured");//configure login callback action- var authenticationProperties = new AuthenticationProperties- {+ var authenticationProperties = new AuthenticationProperties {RedirectUri = Url.Action("GoogleLoginCallback", "GoogleAuthentication", new { returnUrl = returnUrl })};@@ -119,8 +57,7 @@ namespace Authentication.Google.Controllersreturn RedirectToRoute("Login");//create external authentication parameters- var authenticationParameters = new ExternalAuthParam- {+ var authenticationParameters = new ExternalAuthParam {ProviderSystemName = GoogleAuthenticationDefaults.ProviderSystemName,AccessToken = await HttpContext.GetTokenAsync(GoogleDefaults.AuthenticationScheme, "access_token"),Email = authenticateResult.Principal.FindFirst(claim => claim.Type == ClaimTypes.Email)?.Value,@@ -136,11 +73,10 @@ namespace Authentication.Google.Controllerspublic IActionResult GoogleSignInFailed(string error_message){//handle exception and display message to user- var model = new FailedModel()- {+ var model = new FailedModel() {ErrorMessage = error_message};- return View("~/Plugins/Authentication.Google/Views/SignInFailed.cshtml", model);+ return View(model);}#endregion}diff --git a/src/Plugins/Authentication.Google/GoogleAuthenticationDefaults.cs b/src/Plugins/Authentication.Google/GoogleAuthenticationDefaults.csindex 7b6c59101..808c3a72f 100644--- a/src/Plugins/Authentication.Google/GoogleAuthenticationDefaults.cs+++ b/src/Plugins/Authentication.Google/GoogleAuthenticationDefaults.cs@@ -11,6 +11,6 @@ namespace Authentication.Google/// </summary>public const string ProviderSystemName = "ExternalAuth.Google";- public const string ConfigurationUrl = "../GoogleAuthentication/Configure";+ public const string ConfigurationUrl = "../GoogleAuthenticationSettings/Configure";}}diff --git a/src/Plugins/Authentication.Google/Views/SignInFailed.cshtml b/src/Plugins/Authentication.Google/Views/GoogleAuthentication/GoogleSignInFailed.cshtmlsimilarity index 100%rename from src/Plugins/Authentication.Google/Views/SignInFailed.cshtmlrename to src/Plugins/Authentication.Google/Views/GoogleAuthentication/GoogleSignInFailed.cshtmldiff --git a/src/Plugins/Authentication.Google/Views/PublicInfo.cshtml b/src/Plugins/Authentication.Google/Views/Shared/Components/GoogleAuthentication/Default.cshtmlsimilarity index 100%rename from src/Plugins/Authentication.Google/Views/PublicInfo.cshtmlrename to src/Plugins/Authentication.Google/Views/Shared/Components/GoogleAuthentication/Default.cshtml