BMC: Validate Ulr From CompanyMaster

This commit is contained in:
Palash Biswas 2022-12-26 18:36:05 +05:30
parent 097f0f1378
commit 974989b60a
9 changed files with 82 additions and 87 deletions

View File

@ -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<bool> GetUrlIsValid(string url)
public async Task<ValidUrlResponseDto> 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)
{

View File

@ -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; }
}
}

View File

@ -28,6 +28,6 @@ namespace BCS.BMC.CompanyMasters
Task DeleteCompany(EntityDto<int> input);
[HttpPost]
Task<HttpStatusCodeResult> TokenByCompanyUrl(GetInputUrl input);
Task<bool> GetUrlIsValid(string url);
Task<ValidUrlResponseDto> UrlIsValid(string url);
}
}

View File

@ -29,5 +29,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public List<string> UserId { get; set; }
[FirestoreProperty]
public int CompanyId { get; set; }
[FirestoreProperty]
public Guid? ScheduleGenerationId { get; set; }
}
}

View File

@ -24,7 +24,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public bool Status { get; set; }
public List<string> UserId { get; set; }
public string CompanyUrl { get; set; }
public Guid? ScheduleGenerationId { get; set; }
}
//[AutoMapFrom(typeof(NotificationModel))]

View File

@ -126,5 +126,7 @@
<text name="CompanyMaster">Company Master</text>
<text name="Url">Url</text>
<text name="Id">Id</text>
<text name="CreateNewCompany">Create New Company</text>
<text name="EditCompany">Edit Company</text>
</texts>
</localizationDictionary>

View File

@ -12,7 +12,7 @@
<div class="modal fade" id="ClientMasterCreateModal" tabindex="-1" role="dialog" aria-labelledby="UserCreateModalLabel" data-backdrop="static">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
@* @await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("CreateNewUser")))*@
@await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("CreateNewCompany")))
<form name="clientMasterCreateForm" role="form" class="form-horizontal">
<div class="modal-body">
@*<ul class="nav nav-tabs" role="tablist">
@ -26,17 +26,17 @@
<div class="tab-content mt-4">
<div role="tabpanel" class="tab-pane container active" id="create-client-details">
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Url" name="Url" required maxlength="@AbpUserBase.MaxNameLength">
<label class="col-md-2 col-form-label">@L("Url")</label>
<div class="col-md-8">
<input type="text" class="form-control" id="Url" name="Url" required>
</div>
@* <input type="submit" value="Check Url" class="download-button" name="submit">*@
<input type="submit" value="Check Url" class="btn btn-secondary btn-sm download-button" name="submit">
</div>
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Company")</label>
<div class="col-md-9">
<input type="text" class="form-control" name="CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
<div class="form-group row" id="div_CompanyName" style="visibility : hidden">
<label class="col-md-2 col-form-label">@L("Company")</label>
<div class="col-md-8">
<input type="text" class="form-control" name="CompanyName" id="CompanyName" readonly>
</div>
</div>
@* <div class="form-group row required">

View File

@ -6,7 +6,7 @@
@{
Layout = null;
}
@await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("EditCompany")))
<form name="EditCompanyForm" role="form" class="form-horizontal">
<input type="hidden" name="Id" value="@Model.Id" />
<input type="hidden" name="DomainName" value="@Model.DomainName" />
@ -23,18 +23,20 @@
</ul>*@
<div class="tab-content mt-4">
<div role="tabpanel" class="tab-pane container active" id="edit-company-details">
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9">
<input id="url" type="text" class="form-control" name="Url" value="@Model.Url" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div>
</div>
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Company")</label>
<div class="col-md-9">
<input id="CompanyName" type="text" class="form-control" name="CompanyName" value="@Model.CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div>
</div>
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Domain")</label>
<div class="col-md-9">
<input id="url" type="text" class="form-control" name="Url" value="@Model.Url" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div>
</div>
@* <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label>
<div class="col-md-9">

View File

@ -1,9 +1,9 @@
(function ($) {
var _companyService = abp.services.app.companyMaster
l = abp.localization.getSource('BMC'),
_$modal = $('#ClientMasterCreateModal'),
l = abp.localization.getSource('BMC'),
_$modal = $('#ClientMasterCreateModal'),
_$form = _$modal.find('form'),
_$table = $('#CompanyMasterTable');
_$table = $('#CompanyMasterTable');
var _$companyTable = _$table.DataTable({
paging: true,
@ -42,12 +42,12 @@
targets: 2,
data: 'companyName',
sortable: false
}, {
targets: 3,
data: 'url',
sortable: false
},{
sortable: false
}, {
targets: 4,
data: 'domainName',
sortable: false
@ -56,7 +56,7 @@
targets: 5,
data: 'subDomainName',
sortable: false
},{
}, {
targets: 6,
data: null,
sortable: false,
@ -70,7 +70,7 @@
` <button type="button" class="btn btn-sm bg-danger delete-company" data-tenant-id="${row.id}" data-company-name="${row.name}">`,
` <i class="fas fa-trash"></i> ${l('Delete')}`,
' </button>'
].join('');
}
}
@ -84,53 +84,20 @@
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
//function validateUrl (isValid) {
// var companydetails = _$form.serializeFormToObject();
// abp.ui.setBusy();
// var companyUrl = companydetails.Url;
// abp.notify.info(l('ValidatingUrl'));
// _companyService.urlIsValid(companyUrl);
_$form.find('.download-button').on('click', (e) => {
e.preventDefault();
var companydetails = _$form.serializeFormToObject();
//abp.ui.setBusy();
var companyUrl = companydetails.Url;
//}
//_$form.find('.download-button').on('click', (e) => {
// debugger;
// var companydetails = _$form.serializeFormToObject();
// //abp.ui.setBusy();
// var companyUrl = companydetails.Url;
// $.ajax({
// url: abp.appPath + 'CompanyMaster/GetUrlIsValid?url=' + companyUrl,
// type: 'GET',
// data: { url: companyUrl },
// success: function (data) {
// alert('ok');
// console.log(data);
abp.notify.info(l('ValidatingUrl'));
var data = _companyService.urlIsValid(companyUrl);
data.done(function (result) {
$('#div_CompanyName').attr("style", "visibility : visible");
$('#CompanyName').val(result.tenantName);
});
})
// if (data.result == true) {
// debugger;
// alert('correct');
// // window.location.replace("Management Page.aspx");
// }
// },
// Error: function () {
// alert('error');
// }
// });
// //var companydetails = _$form.serializeFormToObject();
// //abp.ui.setBusy();
// //var companyUrl = companydetails.Url;
// //var data = _companyService.getUrlIsValid(companyUrl);
// //data.done(function (result) {
// // var isSuccess = result;
// //})
// //console.log("Hello world!");
// //console.log('1', data);
// //});
//});
_$form.find('.save-button').on('click', (e) => {
e.preventDefault();