Commit f46774c7 authored by Romain Loth's avatar Romain Loth

small harmonizations for validation on client-side

parent 584c89a3
...@@ -159,23 +159,14 @@ if __name__ == "__main__": ...@@ -159,23 +159,14 @@ if __name__ == "__main__":
got_them_all = None got_them_all = None
if captcha_accepted: if captcha_accepted:
expected = ['email', 'hon_title', 'first_name', 'middle_name',
'last_name', 'initials', 'keywords', 'country',
'organization']
columns = ['email', 'initials']
# read in + sanitize values # read in + sanitize values
# ========================= # =========================
# NB password values have already been sent by ajax to Doors # NB password values have already been sent by ajax to Doors
# TODO redundant with js validation ? # we should have all the mandatory fields (checked in client-side js)
for field in COLS: for field in COLS:
if field in incoming_data: if (field in incoming_data) and (field != pic_file):
clean_records[field] = sanitize(incoming_data[field].value) clean_records[field] = sanitize(incoming_data[field].value)
else:
missing_fields.append(field)
# --------- todo ------>8-------------- # --------- todo ------>8--------------
# optional # optional
...@@ -184,18 +175,8 @@ if __name__ == "__main__": ...@@ -184,18 +175,8 @@ if __name__ == "__main__":
# picture_bytes = picture.value # picture_bytes = picture.value
# --------------------->8--------------- # --------------------->8---------------
# debug data keys # save to DB
# print([k for k in incoming_data]) # ===========
# NB will be done in js
got_them_all = True
for k in columns:
if k in missing_fields:
got_them_all = False
break
# sanitize & save to DB
# =====================
save_to_db([clean_records[k] for k in columns]) save_to_db([clean_records[k] for k in columns])
...@@ -207,7 +188,7 @@ if __name__ == "__main__": ...@@ -207,7 +188,7 @@ if __name__ == "__main__":
# for debug # for debug
records = clean_records, records = clean_records,
message = "got_them_all:" + str(got_them_all) message = ""
) )
) )
......
...@@ -24,6 +24,8 @@ var COLS = [ ["doors_uid", false, 36, 'exact'], ...@@ -24,6 +24,8 @@ var COLS = [ ["doors_uid", false, 36, 'exact'],
var wholeFormData var wholeFormData
var theForm = document.getElementById('comex_reg_form') var theForm = document.getElementById('comex_reg_form')
var regTimestamp = document.getElementById('last_modified_date') var regTimestamp = document.getElementById('last_modified_date')
var uidInput = document.getElementById('doors_uid')
var email = document.getElementById('email')
var subPage1Style = document.getElementById('subpage_1').style var subPage1Style = document.getElementById('subpage_1').style
var subPage2Style = document.getElementById('subpage_2').style var subPage2Style = document.getElementById('subpage_2').style
...@@ -56,9 +58,12 @@ var emailStatus = false ...@@ -56,9 +58,12 @@ var emailStatus = false
var captchaStatus = false var captchaStatus = false
submitButton.disabled = true submitButton.disabled = true
theForm.onkeyup = beTestedAsYouGo theForm.onkeyup = beTestedAsYouGo
theForm.onchange = beTestedAsYouGo
// done when anything in the form changes // done when anything in the form changes
function beTestedAsYouGo() { function beTestedAsYouGo() {
basicEmailValidate()
captchaStatus = (captcha.value.length == realCaptchaLength)
if (passStatus && emailStatus && captchaStatus) { if (passStatus && emailStatus && captchaStatus) {
submitButton.disabled = false submitButton.disabled = false
} }
...@@ -157,6 +162,7 @@ function validateSubmit(e, orignStr, loginOrRegister) { ...@@ -157,6 +162,7 @@ function validateSubmit(e, orignStr, loginOrRegister) {
doorsUid = makePseudoDoorsUid() doorsUid = makePseudoDoorsUid()
// 3) fill in the answer we got // 3) fill in the answer we got
wholeFormData.set("doors_uid", doorsUid) wholeFormData.set("doors_uid", doorsUid)
uidInput.value = doorsUid // todo feels redundant (=> refactor submit into FormData send ?)
// 4) here entire validation // 4) here entire validation
...@@ -214,6 +220,9 @@ function validateSubmit(e, orignStr, loginOrRegister) { ...@@ -214,6 +220,9 @@ function validateSubmit(e, orignStr, loginOrRegister) {
// 5) RESULTS // 5) RESULTS
if (valid) { if (valid) {
// add the captchaCheck inside the form (jquery interference)
captchaCheck.value = $(captcha).realperson('getHash')
mainMessage.innerHTML = "Form is valid... Submitting..." mainMessage.innerHTML = "Form is valid... Submitting..."
mainMessage.style.display = 'block' mainMessage.style.display = 'block'
theForm.submit() theForm.submit()
...@@ -340,10 +349,7 @@ nameInputs.forEach ( function(nameInput) { ...@@ -340,10 +349,7 @@ nameInputs.forEach ( function(nameInput) {
// very basic email validation TODO: better extension and allowed chars set :) // very basic email validation TODO: better extension and allowed chars set :)
var email = document.getElementById('email') // (used in tests "as we go")
email.onkeyup = basicEmailValidate
email.onblur = basicEmailValidate
function basicEmailValidate () { function basicEmailValidate () {
emailStatus = /^[-A-z0-9_=.+]+@[-A-z0-9_=.+]+\.[-A-z0-9_=.+]{1,4}$/.test(email.value) emailStatus = /^[-A-z0-9_=.+]+@[-A-z0-9_=.+]+\.[-A-z0-9_=.+]{1,4}$/.test(email.value)
} }
...@@ -389,12 +395,6 @@ passwords.forEach ( function(pass) { ...@@ -389,12 +395,6 @@ passwords.forEach ( function(pass) {
}) })
var captcha = document.getElementById('my-captcha')
captcha.onkeyup = function() {
captchaStatus = (captcha.value.length == realCaptchaLength)
}
// autocomplete countries // autocomplete countries
$(function() { $(function() {
var $countryInput = $('#country') var $countryInput = $('#country')
...@@ -624,6 +624,7 @@ $('#my-captcha').val('') ...@@ -624,6 +624,7 @@ $('#my-captcha').val('')
$(function() { $(function() {
var $kwInput = $('#keywords') var $kwInput = $('#keywords')
// TODO transform into simple array => faster
var kwFreqs = { var kwFreqs = {
"complex networks": 154, "complex networks": 154,
"complex systems": 134, "complex systems": 134,
...@@ -983,3 +984,5 @@ $(function() { ...@@ -983,3 +984,5 @@ $(function() {
} }
}); });
}); });
console.log("load OK")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment