VRFS-2697 url format and site validation
This commit is contained in:
parent
6069399a55
commit
fdcc77ae80
|
|
@ -1478,6 +1478,14 @@
|
|||
});
|
||||
}
|
||||
|
||||
function validateUrl(url) {
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/data_validation?data=' + encodeURIComponent(url),
|
||||
contentType: 'application/json'
|
||||
});
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
return self;
|
||||
}
|
||||
|
|
@ -1608,6 +1616,7 @@
|
|||
this.resendBandInvitation = resendBandInvitation;
|
||||
this.getMount = getMount;
|
||||
this.createSourceChange = createSourceChange;
|
||||
this.validateUrl = validateUrl;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,18 +3,21 @@ context = window
|
|||
context.JK ||= {};
|
||||
|
||||
context.JK.WebsiteValidator = class WebsiteValidator
|
||||
constructor: (@app, input_obj) ->
|
||||
constructor: (@app, input_div) ->
|
||||
@EVENTS = context.JK.EVENTS
|
||||
@rest = context.JK.Rest()
|
||||
@url_input = input_obj
|
||||
@input_div = input_div
|
||||
@url_input = @input_div.find('input')
|
||||
this.show_validation_status()
|
||||
@logger = context.JK.logger
|
||||
|
||||
init: () =>
|
||||
validator = this;
|
||||
@url_input.bind 'blur', ->
|
||||
yn = validator.validate_url()
|
||||
alert 'invalid' unless yn
|
||||
alert 'invalid' unless validator.show_validation_status()
|
||||
validator.validate_url_site()
|
||||
|
||||
validate_url: () =>
|
||||
validate_url_format: () =>
|
||||
url = @url_input.val()
|
||||
if 0 < url.length
|
||||
regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
|
|
@ -22,3 +25,24 @@ context.JK.WebsiteValidator = class WebsiteValidator
|
|||
else
|
||||
true
|
||||
|
||||
show_validation_status: () =>
|
||||
yn = this.validate_url_format()
|
||||
if yn
|
||||
@input_div.find('.valid_checkmark').show()
|
||||
else
|
||||
@input_div.find('.valid_checkmark').hide()
|
||||
yn
|
||||
|
||||
validate_url_site: () =>
|
||||
@rest.validateUrl(@url_input.val(), context.JK.currentUserId)
|
||||
.done(this.processDidValidate)
|
||||
.fail(this.processDidNotValidate)
|
||||
|
||||
processDidValidate: (response) =>
|
||||
if 'valid' == response.message
|
||||
@logger.debug("is valid")
|
||||
else if 'invalid' == response.message
|
||||
@logger.debug("is not valid")
|
||||
|
||||
processDidNotValidate: () =>
|
||||
@logger.error("is not valid ... error")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
@import "client/common";
|
||||
|
||||
.website_validator {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
float: left;
|
||||
}
|
||||
.valid_checkmark {
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require 'sanitize'
|
||||
class ApiUsersController < ApiController
|
||||
|
||||
before_filter :api_signed_in_user, :except => [:create, :show, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring, :add_play, :crash_dump]
|
||||
before_filter :api_signed_in_user, :except => [:create, :show, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring, :add_play, :crash_dump, :validate_data]
|
||||
before_filter :auth_user, :only => [:session_settings_show, :session_history_index, :session_user_history_index, :update, :delete,
|
||||
:liking_create, :liking_destroy, # likes
|
||||
:following_create, :following_show, :following_destroy, # followings
|
||||
|
|
@ -699,6 +699,23 @@ class ApiUsersController < ApiController
|
|||
end
|
||||
end
|
||||
|
||||
def validate_data
|
||||
data = params[:data]
|
||||
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
|
||||
else
|
||||
render json: { message: "blank data #{data}" }, status: :unprocessable_entity
|
||||
end
|
||||
return
|
||||
elsif 'username' == vtype
|
||||
end
|
||||
|
||||
render json: { message: "unknown validation type #{params[:validation_type]}" }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
###################### RECORDINGS #######################
|
||||
# def recording_index
|
||||
# @recordings = User.recording_index(current_user, params[:id])
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
input type='text' id="website_#{siteid}" class="website_validator"
|
||||
|
||||
div class="website_validator" id="#{siteid}_url"
|
||||
div class="valid_checkmark" ✓
|
||||
input type='text' id="url_input_#{siteid}"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ javascript:
|
|||
var initialized = false;
|
||||
$(document).on('JAMKAZAM_READY', function(e, data) {
|
||||
setTimeout(function() {
|
||||
window.website_validator = new JK.WebsiteValidator(data.app, $("#website_foobar"))
|
||||
window.website_validator = new JK.WebsiteValidator(data.app, $(".website_validator#foobar_url"))
|
||||
website_validator.init()
|
||||
$('#website_foobar').val('http://www.jamkazam.com')
|
||||
$('#url_input_foobar').val('http://www.jamkazam.com')
|
||||
}, 1)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ SampleApp::Application.routes.draw do
|
|||
# users
|
||||
match '/users/isp_scoring' => 'api_users#isp_scoring', :via => :post , :as => 'isp_scoring'
|
||||
|
||||
# validation
|
||||
match '/data_validation' => 'api_users#validate_data', :via => :get
|
||||
|
||||
match '/users' => 'api_users#index', :via => :get
|
||||
match '/users/:id' => 'api_users#show', :via => :get, :as => 'api_user_detail'
|
||||
#match '/users' => 'api_users#create', :via => :post
|
||||
|
|
|
|||
Loading…
Reference in New Issue