VRFS-2697 enhanced error handling; crop url length
This commit is contained in:
parent
abb5c3afb2
commit
9086fac76a
|
|
@ -1478,7 +1478,7 @@
|
|||
});
|
||||
}
|
||||
|
||||
function validateUrl(url) {
|
||||
function validateUrlSite(url) {
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/data_validation?data=' + encodeURIComponent(url),
|
||||
|
|
@ -1616,7 +1616,7 @@
|
|||
this.resendBandInvitation = resendBandInvitation;
|
||||
this.getMount = getMount;
|
||||
this.createSourceChange = createSourceChange;
|
||||
this.validateUrl = validateUrl;
|
||||
this.validateUrlSite = validateUrlSite;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,28 +3,37 @@ context = window
|
|||
context.JK ||= {};
|
||||
|
||||
context.JK.WebsiteValidator = class WebsiteValidator
|
||||
|
||||
constructor: (@app, input_div) ->
|
||||
@EVENTS = context.JK.EVENTS
|
||||
@rest = context.JK.Rest()
|
||||
@input_div = input_div
|
||||
@url_input = @input_div.find('input')
|
||||
this.show_validation_status()
|
||||
this.show_format_status()
|
||||
@logger = context.JK.logger
|
||||
@site_status = null
|
||||
|
||||
init: () =>
|
||||
validator = this;
|
||||
validator = this
|
||||
@url_input.bind 'blur', ->
|
||||
alert 'invalid' unless validator.show_validation_status()
|
||||
if validator.show_format_status()
|
||||
validator.validate_url_site()
|
||||
|
||||
validate_url_format: () =>
|
||||
regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
regexp.test(@url_input.val())
|
||||
|
||||
show_validation_status: () =>
|
||||
url_to_validate: () =>
|
||||
url = @url_input.val()
|
||||
yn = true
|
||||
if 0 < url.length
|
||||
url.substring(0,2000)
|
||||
else
|
||||
null
|
||||
|
||||
validate_url_format: () =>
|
||||
regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
regexp.test(this.url_to_validate())
|
||||
|
||||
show_format_status: () =>
|
||||
url = this.url_to_validate()
|
||||
yn = true
|
||||
if url
|
||||
yn = this.validate_url_format()
|
||||
if yn
|
||||
@input_div.find('.valid_checkmark').show()
|
||||
|
|
@ -33,15 +42,18 @@ context.JK.WebsiteValidator = class WebsiteValidator
|
|||
yn
|
||||
|
||||
validate_url_site: () =>
|
||||
@rest.validateUrl(@url_input.val(), context.JK.currentUserId)
|
||||
.done(this.processDidValidate)
|
||||
.fail(this.processDidNotValidate)
|
||||
@site_status = null
|
||||
@rest.validateUrlSite(this.url_to_validate())
|
||||
.done(this.processSiteCheck)
|
||||
.fail(this.processSiteCheckFail)
|
||||
|
||||
processDidValidate: (response) =>
|
||||
if 'valid' == response.message
|
||||
@logger.debug("is valid")
|
||||
else if 'invalid' == response.message
|
||||
@logger.debug("is not valid")
|
||||
processSiteCheck: (response) =>
|
||||
if 'Valid Site' == response.message
|
||||
@site_status = 'valid'
|
||||
else
|
||||
@site_status = 'invalid'
|
||||
@logger.debug("site_status = "+@site_status)
|
||||
|
||||
processDidNotValidate: () =>
|
||||
@logger.error("is not valid ... error")
|
||||
processSiteCheckFail: () =>
|
||||
@logger.error("site check error")
|
||||
@site_status = 'invalid'
|
||||
|
|
|
|||
|
|
@ -704,8 +704,13 @@ class ApiUsersController < ApiController
|
|||
vtype = data =~ /^http/ ? 'url' : 'username'
|
||||
if 'url' == vtype
|
||||
if data.present?
|
||||
`curl --output /dev/null --silent --head --fail --show-error '#{data}'`
|
||||
render json: { message: $?.success? ? 'valid' : 'invalid' }, status: 200
|
||||
result = `curl --output /dev/null --silent --head --fail --show-error '#{data}' 2>&1`.chomp
|
||||
if $?.success?
|
||||
render json: { message: 'Valid Site' }, status: 200
|
||||
else
|
||||
result =~ /curl: \(\d+\) (.*)/
|
||||
render json: { message: 'Invalid Site', errors: [$1] }, status: 200
|
||||
end
|
||||
else
|
||||
render json: { message: "blank data #{data}" }, status: :unprocessable_entity
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
div class="website_validator" id="#{siteid}_url"
|
||||
div class="valid_checkmark" ✓
|
||||
input type='text' id="url_input_#{siteid}"
|
||||
input type='text' id="url_input_#{siteid}" maxlength="2000"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue