From 974989b60a2d5b37592471a137603001ad52a1bd Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Mon, 26 Dec 2022 18:36:05 +0530 Subject: [PATCH] BMC: Validate Ulr From CompanyMaster --- .../CompanyMasters/CompanyMasterAppService.cs | 40 ++++++---- .../CompanyMasters/Dto/ValidUrlResponseDto.cs | 14 ++++ .../ICompanyMasterAppService.cs | 2 +- .../Dto/FireStoreNotificationModel.cs | 2 + .../Dto/NotificationModel.cs | 2 +- .../Localization/SourceFiles/BMC.xml | 2 + .../Views/CompanyMaster/_CreateModal.cshtml | 18 ++--- .../Views/CompanyMaster/_EditModal.cshtml | 12 +-- .../Views/CompanyMaster/Index.js | 75 ++++++------------- 9 files changed, 81 insertions(+), 86 deletions(-) create mode 100644 BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs diff --git a/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs index 1c765cf..2049fce 100644 --- a/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs @@ -37,6 +37,7 @@ using System.Net.Http.Headers; using Newtonsoft.Json; using Abp.Json; using System.Diagnostics; +using static Grpc.Core.Metadata; namespace BCS.BMC.CompanyMasters { @@ -158,10 +159,13 @@ namespace BCS.BMC.CompanyMasters return companyId; } - public async Task GetUrlIsValid(string url) + public async Task UrlIsValid(string url) { + bool istrue = false; + var entity= new ValidUrlResponseDto(); try { + HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Timeout = 5000; //set the timeout to 5 seconds to keep the user from waiting too long for the page to load request.Method = "HEAD"; //Get only the header information -- no need to download any content @@ -171,32 +175,36 @@ namespace BCS.BMC.CompanyMasters int statusCode = (int)response.StatusCode; if (statusCode >= 100 && statusCode < 400) //Good requests { - return true; + entity.IsSuccess = true; + Uri uri = new Uri(url, UriKind.Absolute); + var host = uri.Host; + + if (host.Split('.').Length > 2) + { + int lastIndex = host.LastIndexOf("."); + int index = host.LastIndexOf(".", lastIndex - 1); + var subdomain = host.Substring(0, index); + if (subdomain != "www") + { + entity.TenantName = subdomain; + } + } } else if (statusCode >= 500 && statusCode <= 510) //Server Errors { //log.Warn(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url)); Debug.WriteLine(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url)); - return false; + istrue = false; } + } - } - catch (WebException ex) - { - if (ex.Status == WebExceptionStatus.ProtocolError) //400 errors - { - return false; - } - else - { - // log.Warn(String.Format("Unhandled status [{0}] returned for url: {1}", ex.Status, url), ex); - } - } + + } catch (Exception ex) { // log.Error(String.Format("Could not test url {0}.", url), ex); } - return false; + return entity; } protected async Task Update(CreateOrUpdateCompanyMasterInput input) { diff --git a/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs new file mode 100644 index 0000000..1318e23 --- /dev/null +++ b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BCS.BMC.CompanyMasters.Dto +{ + public class ValidUrlResponseDto + { + public bool IsSuccess { get; set; } + public string TenantName { get; set; } + } +} diff --git a/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs index 6989a93..ea31b43 100644 --- a/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs @@ -28,6 +28,6 @@ namespace BCS.BMC.CompanyMasters Task DeleteCompany(EntityDto input); [HttpPost] Task TokenByCompanyUrl(GetInputUrl input); - Task GetUrlIsValid(string url); + Task UrlIsValid(string url); } } diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs index d5e3ecf..b03a1fe 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs @@ -29,5 +29,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public List UserId { get; set; } [FirestoreProperty] public int CompanyId { get; set; } + [FirestoreProperty] + public Guid? ScheduleGenerationId { get; set; } } } diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs index 63564bf..3c6f03c 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -24,7 +24,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public bool Status { get; set; } public List UserId { get; set; } public string CompanyUrl { get; set; } - + public Guid? ScheduleGenerationId { get; set; } } //[AutoMapFrom(typeof(NotificationModel))] diff --git a/BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml b/BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml index b0eae11..b39af40 100644 --- a/BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml +++ b/BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml @@ -126,5 +126,7 @@ Company Master Url Id + Create New Company + Edit Company diff --git a/BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml b/BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml index 29cb284..3c21d90 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml @@ -12,7 +12,7 @@