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