Commit c4c42a6c authored by Romain Loth's avatar Romain Loth

debug dbwrite (wip:TODO re-enable doors)

parent b6071676
...@@ -353,6 +353,10 @@ ...@@ -353,6 +353,10 @@
<input id="doors_uid" name="doors_uid" type="text" hidden> <input id="doors_uid" name="doors_uid" type="text" hidden>
</input> </input>
<!-- hidden input for captcha verification hash -->
<input id="my-captchaHash" name="my-captchaHash" type="text" hidden>
</input>
<div class="row spacerrow">&nbsp;</div><div class="row spacerrow">&nbsp;</div> <div class="row spacerrow">&nbsp;</div><div class="row spacerrow">&nbsp;</div>
<!-- CAPTCHA & SUBMIT BTN + INFOS--> <!-- CAPTCHA & SUBMIT BTN + INFOS-->
......
...@@ -105,7 +105,9 @@ def sanitize(value): ...@@ -105,7 +105,9 @@ def sanitize(value):
""" """
vtype = type(value) vtype = type(value)
str_val = str(value) str_val = str(value)
san_val = sub(r'[^\w@\.-:]', '', str_val) clean_val = sub(r'^\s+', '', str_val)
clean_val = sub(r'\s+$', '', clean_val)
san_val = sub(r'[^\w@\.-:]', '', clean_val)
if vtype not in [int, str]: if vtype not in [int, str]:
raise ValueError("Value has an incorrect type %s" % str(vtype)) raise ValueError("Value has an incorrect type %s" % str(vtype))
...@@ -114,18 +116,21 @@ def sanitize(value): ...@@ -114,18 +116,21 @@ def sanitize(value):
san_typed_val = vtype(san_val) san_typed_val = vtype(san_val)
return san_typed_val return san_typed_val
def save_to_db(safe_records): def save_to_db(safe_recs_arr):
""" """
see COLS and table_specifications.md see COLS and table_specifications.md
""" """
# expected number of vals (for instance 3 vals ===> "(?,?,?)" )
db_mask = '('+ ','.join(['?' for i in range(len(COLS))]) + ')'
# £TODO check if email exists first # £TODO check if email exists first
# yes =>propose login via doors + overwrite ?) # yes =>propose login via doors + overwrite ?)
# no => proceed # no => proceed
reg_db = connect('../data/registered.db') reg_db = connect('../data/registered.db')
reg_db_c = reg_db.cursor() reg_db_c = reg_db.cursor()
reg_db_c.execute('INSERT INTO test_table VALUES (?,?)', safe_records) reg_db_c.execute('INSERT INTO comex_registrations VALUES' + db_mask , safe_recs_arr)
reg_db.commit() reg_db.commit()
reg_db.close() reg_db.close()
...@@ -156,7 +161,12 @@ if __name__ == "__main__": ...@@ -156,7 +161,12 @@ if __name__ == "__main__":
captcha_accepted = (captcha_userhash == captcha_verifhash) captcha_accepted = (captcha_userhash == captcha_verifhash)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
got_them_all = None # debug data keys
# print_to_buffer(str([k for k in incoming_data]))
# print_to_buffer(str(incoming_data))
# debug doors_uid
# print_to_buffer('doors_uid before clean: '+str(incoming_data['doors_uid']))
if captcha_accepted: if captcha_accepted:
# read in + sanitize values # read in + sanitize values
...@@ -175,9 +185,12 @@ if __name__ == "__main__": ...@@ -175,9 +185,12 @@ if __name__ == "__main__":
# picture_bytes = picture.value # picture_bytes = picture.value
# --------------------->8--------------- # --------------------->8---------------
# debug doors_uid
# print_to_buffer('doors_uid after clean: '+clean_records['doors_uid'])
# save to DB # save to DB
# =========== # ===========
save_to_db([clean_records[k] for k in columns]) save_to_db([clean_records.get(k, None) for k in COLS])
# show received values in template # show received values in template
......
...@@ -27,6 +27,11 @@ var regTimestamp = document.getElementById('last_modified_date') ...@@ -27,6 +27,11 @@ var regTimestamp = document.getElementById('last_modified_date')
var uidInput = document.getElementById('doors_uid') var uidInput = document.getElementById('doors_uid')
var email = document.getElementById('email') var email = document.getElementById('email')
// captchaHash should be appended by itself if normal submit,
// but we need to do it ourselves (b/c of validateSubmit ?)
var captcha = document.getElementById('my-captcha')
var captchaCheck = document.getElementById('my-captchaHash')
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
var teamCityDivStyle = document.getElementById('team_city_div').style var teamCityDivStyle = document.getElementById('team_city_div').style
...@@ -59,6 +64,7 @@ var captchaStatus = false ...@@ -59,6 +64,7 @@ var captchaStatus = false
submitButton.disabled = true submitButton.disabled = true
theForm.onkeyup = beTestedAsYouGo theForm.onkeyup = beTestedAsYouGo
theForm.onchange = beTestedAsYouGo theForm.onchange = beTestedAsYouGo
theForm.onblur = beTestedAsYouGo
// done when anything in the form changes // done when anything in the form changes
function beTestedAsYouGo() { function beTestedAsYouGo() {
......
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