Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
f46774c7
Commit
f46774c7
authored
Nov 17, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small harmonizations for validation on client-side
parent
584c89a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
34 deletions
+18
-34
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+5
-24
comex_reg_form_controllers.js
static/js/comex_reg_form_controllers.js
+13
-10
No files found.
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
f46774c7
...
@@ -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
=
"
"
)
)
)
)
...
...
static/js/comex_reg_form_controllers.js
View file @
f46774c7
...
@@ -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"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment