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
3f2554e9
Commit
3f2554e9
authored
Feb 23, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
esthetic (clarify comments and var names) + generalize passing db connection as arg
parent
9d295310
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
79 deletions
+127
-79
db.py
services/db.py
+100
-56
main.py
services/main.py
+24
-19
user.py
services/user.py
+2
-3
comex_user_shared_auth.js
static/js/comex_user_shared_auth.js
+1
-1
No files found.
services/db.py
View file @
3f2554e9
This diff is collapsed.
Click to expand it.
services/main.py
View file @
3f2554e9
...
@@ -98,9 +98,9 @@ SOURCE_FIELDS = [
...
@@ -98,9 +98,9 @@ SOURCE_FIELDS = [
(
"hon_title"
,
True
,
None
),
(
"hon_title"
,
True
,
None
),
(
"interests_text"
,
True
,
None
),
(
"interests_text"
,
True
,
None
),
(
"gender"
,
False
,
None
),
# M|F
(
"gender"
,
False
,
None
),
# M|F
(
"job_looking_date"
,
True
,
"date"
),
# def null: not looking for a job
(
"job_looking_date"
,
True
,
"
s
date"
),
# def null: not looking for a job
(
"home_url"
,
True
,
"
url"
),
# scholar's homepage
(
"home_url"
,
True
,
"s
url"
),
# scholar's homepage
(
"pic_url"
,
True
,
"
url"
),
(
"pic_url"
,
True
,
"s
url"
),
(
"pic_file"
,
False
,
None
),
# saved separately
(
"pic_file"
,
False
,
None
),
# saved separately
# => for *scholars* table (optional)
# => for *scholars* table (optional)
...
@@ -132,13 +132,13 @@ def inject_doors_params():
...
@@ -132,13 +132,13 @@ def inject_doors_params():
-> 'doors_connect'
-> 'doors_connect'
(base_layout-rendered templates need it for login popup)
(base_layout-rendered templates need it for login popup)
"""
"""
if
'DOORS_PORT'
not
in
config
or
config
[
'DOORS_PORT'
]
in
[
'
'
,
'
80'
,
'443'
]:
if
'DOORS_PORT'
not
in
config
or
config
[
'DOORS_PORT'
]
in
[
'80'
,
'443'
]:
context_dict
=
dict
(
context_dict
=
dict
(
doors_connect
=
config
[
'DOORS_HOST'
]
doors_connect
=
config
[
'DOORS_HOST'
]
)
)
else
:
else
:
context_dict
=
dict
(
context_dict
=
dict
(
doors_connect
=
config
[
'DOORS_HOST'
]
doors_connect
=
config
[
'DOORS_HOST'
]
+
':'
+
config
[
'DOORS_PORT'
]
)
)
return
context_dict
return
context_dict
...
@@ -252,7 +252,8 @@ def user_api():
...
@@ -252,7 +252,8 @@ def user_api():
implemented "op" <=> verbs:
implemented "op" <=> verbs:
exists => bool
exists => bool
"""
"""
if
'op'
in
request
.
args
and
request
.
args
[
'op'
]
==
"exists"
:
if
'op'
in
request
.
args
:
if
request
.
args
[
'op'
]
==
"exists"
:
if
'email'
in
request
.
args
:
if
'email'
in
request
.
args
:
email
=
sanitize
(
request
.
args
[
'email'
])
email
=
sanitize
(
request
.
args
[
'email'
])
return
(
dumps
({
'exists'
:
db
.
email_exists
(
email
)}))
return
(
dumps
({
'exists'
:
db
.
email_exists
(
email
)}))
...
@@ -275,7 +276,7 @@ def login():
...
@@ -275,7 +276,7 @@ def login():
"login.html"
"login.html"
)
)
elif
request
.
method
==
'POST'
:
elif
request
.
method
==
'POST'
:
mlog
(
"DEBUG"
,
"
login
form received from "
+
request
.
path
+
", with keys:"
,
[
k
for
k
in
request
.
values
])
mlog
(
"DEBUG"
,
"
LOGIN:
form received from "
+
request
.
path
+
", with keys:"
,
[
k
for
k
in
request
.
values
])
# we used this custom header to mark ajax calls => called_as_api True
# we used this custom header to mark ajax calls => called_as_api True
x_req_with
=
request
.
headers
.
get
(
'X-Requested-With'
,
type
=
str
)
x_req_with
=
request
.
headers
.
get
(
'X-Requested-With'
,
type
=
str
)
...
@@ -309,10 +310,10 @@ def login():
...
@@ -309,10 +310,10 @@ def login():
try
:
try
:
doors_uid
=
doors_login
(
email
,
pwd
,
config
)
doors_uid
=
doors_login
(
email
,
pwd
,
config
)
except
Exception
as
err
:
except
Exception
as
err
:
mlog
(
"ERROR"
,
"error in doors_login request"
)
mlog
(
"ERROR"
,
"
LOGIN:
error in doors_login request"
)
raise
(
err
)
raise
(
err
)
mlog
(
"DEBUG"
,
"
doors_login
returned doors_uid '
%
s'"
%
doors_uid
)
mlog
(
"DEBUG"
,
"
user.doors_login()
returned doors_uid '
%
s'"
%
doors_uid
)
if
doors_uid
is
None
:
if
doors_uid
is
None
:
# break: can't doors_login
# break: can't doors_login
...
@@ -332,6 +333,7 @@ def login():
...
@@ -332,6 +333,7 @@ def login():
# normal user
# normal user
user
=
User
(
luid
)
user
=
User
(
luid
)
else
:
else
:
mlog
(
"DEBUG"
,
"LOGIN: encountered new doors id (
%
s), switching to empty user profile"
%
doors_uid
)
# user exists in doors but has no comex profile nor luid yet
# user exists in doors but has no comex profile nor luid yet
db
.
save_doors_temp_user
(
doors_uid
,
email
)
# preserve the email
db
.
save_doors_temp_user
(
doors_uid
,
email
)
# preserve the email
user
=
User
(
None
,
doors_uid
=
doors_uid
)
# get a user.empty
user
=
User
(
None
,
doors_uid
=
doors_uid
)
# get a user.empty
...
@@ -354,7 +356,7 @@ def login():
...
@@ -354,7 +356,7 @@ def login():
if
not
login_ok
:
if
not
login_ok
:
# break: failed to login_user()
# break: failed to login_user()
notok_message
=
"There was an unknown problem with the login."
notok_message
=
"
LOGIN
There was an unknown problem with the login."
if
called_as_api
:
if
called_as_api
:
# menubar login will prevent redirect
# menubar login will prevent redirect
return
(
nologin_message
,
404
)
return
(
nologin_message
,
404
)
...
@@ -373,7 +375,7 @@ def login():
...
@@ -373,7 +375,7 @@ def login():
elif
user
.
empty
:
elif
user
.
empty
:
mlog
(
'DEBUG'
,
"empty user redirected to profile"
)
mlog
(
'DEBUG'
,
"empty user redirected to profile"
)
# we go straight to
profile for the him
to create infos
# we go straight to
empty profile for the person
to create infos
return
(
redirect
(
url_for
(
'profile'
,
_external
=
True
)))
return
(
redirect
(
url_for
(
'profile'
,
_external
=
True
)))
# normal call, normal user
# normal call, normal user
...
@@ -392,7 +394,7 @@ def login():
...
@@ -392,7 +394,7 @@ def login():
# if relative
# if relative
if
next_url
[
0
]
==
'/'
:
if
next_url
[
0
]
==
'/'
:
next_url
=
url_for
(
'rootindex'
,
_external
=
True
)
+
next_url
[
1
:]
next_url
=
url_for
(
'rootindex'
,
_external
=
True
)
+
next_url
[
1
:]
mlog
(
"DEBUG"
,
"reabsoluted next_url:"
,
next_url
)
mlog
(
"DEBUG"
,
"
LOGIN:
reabsoluted next_url:"
,
next_url
)
return
(
redirect
(
next_url
))
return
(
redirect
(
next_url
))
else
:
else
:
...
@@ -572,7 +574,10 @@ def claim_profile():
...
@@ -572,7 +574,10 @@ def claim_profile():
luid
=
request
.
form
[
'return_user_luid'
]
luid
=
request
.
form
[
'return_user_luid'
]
return_user
=
User
(
luid
)
return_user
=
User
(
luid
)
name
=
return_user
.
info
.
get
(
'last_name'
)
+
', '
+
return_user
.
info
.
get
(
'first_name'
,
''
)
+
' '
+
return_user
.
info
.
get
(
'middle_name'
,
''
)
info
=
return_user
.
info
name
=
info
[
'last_name'
]
+
', '
+
info
[
'first_name'
]
if
info
[
'middle_name'
]:
name
+=
' '
+
info
[
'middle_name'
]
# we do our doors request here server-side to avoid MiM attack on result
# we do our doors request here server-side to avoid MiM attack on result
try
:
try
:
...
@@ -679,7 +684,7 @@ def register():
...
@@ -679,7 +684,7 @@ def register():
return
render_template
(
return
render_template
(
"thank_you.html"
,
"thank_you.html"
,
debug_records
=
(
clean_records
if
app
.
config
[
'DEBUG'
]
else
{}),
debug_records
=
(
clean_records
if
app
.
config
[
'DEBUG'
]
else
{}),
form_accepted
=
True
,
form_accepted
=
form_accepted
,
backend_error
=
False
,
backend_error
=
False
,
message
=
"""
message
=
"""
You can now visit elements of the members section:
You can now visit elements of the members section:
...
@@ -858,9 +863,9 @@ def sanitize(value, specific_type=None):
...
@@ -858,9 +863,9 @@ def sanitize(value, specific_type=None):
if
not
specific_type
:
if
not
specific_type
:
san_val
=
sub
(
r'[^\w@\.:,()# -]'
,
'_'
,
clean_val
)
san_val
=
sub
(
r'[^\w@\.:,()# -]'
,
'_'
,
clean_val
)
elif
specific_type
==
"url"
:
elif
specific_type
==
"
s
url"
:
san_val
=
sub
(
r'[^\w@\.: -/]'
,
'_'
,
clean_val
)
san_val
=
sub
(
r'[^\w@\.: -/]'
,
'_'
,
clean_val
)
elif
specific_type
==
"date"
:
elif
specific_type
==
"
s
date"
:
san_val
=
sub
(
r'[^0-9/-:]'
,
'_'
,
clean_val
)
san_val
=
sub
(
r'[^0-9/-:]'
,
'_'
,
clean_val
)
if
vtype
not
in
[
int
,
str
]:
if
vtype
not
in
[
int
,
str
]:
...
...
services/user.py
View file @
3f2554e9
...
@@ -79,8 +79,7 @@ class User(object):
...
@@ -79,8 +79,7 @@ class User(object):
doors but not in db)
doors but not in db)
=> no luid, but has doors_uid
=> no luid, but has doors_uid
This also causes trickier behaviour for get_id:
NB load_user() wants a *single id for both*,
ie load_user() wants a *single id for both*,
which is provided by self.get_id()
which is provided by self.get_id()
"""
"""
mlog
(
'DEBUG'
,
mlog
(
'DEBUG'
,
...
@@ -225,7 +224,6 @@ def doors_login(email, password, config=REALCONFIG):
...
@@ -225,7 +224,6 @@ def doors_login(email, password, config=REALCONFIG):
http_scheme
=
"https:"
http_scheme
=
"https:"
# (TODO generalize this logic)
if
config
[
'DOORS_PORT'
]
in
[
'80'
,
'443'
]:
if
config
[
'DOORS_PORT'
]
in
[
'80'
,
'443'
]:
# implicit port
# implicit port
doors_base_url
=
http_scheme
+
'//'
+
config
[
'DOORS_HOST'
]
doors_base_url
=
http_scheme
+
'//'
+
config
[
'DOORS_HOST'
]
...
@@ -276,6 +274,7 @@ def doors_register(email, password, name, config=REALCONFIG):
...
@@ -276,6 +274,7 @@ def doors_register(email, password, name, config=REALCONFIG):
# eg doors_response.content = b'{"status":"registration email sent",
# eg doors_response.content = b'{"status":"registration email sent",
# "email":"john@locke.com"}''
# "email":"john@locke.com"}''
answer
=
loads
(
doors_response
.
content
.
decode
())
answer
=
loads
(
doors_response
.
content
.
decode
())
mlog
(
"INFO"
,
"/api/register answer"
,
answer
)
return
answer
[
'userID'
]
return
answer
[
'userID'
]
else
:
else
:
return
None
return
None
static/js/comex_user_shared_auth.js
View file @
3f2554e9
...
@@ -71,7 +71,7 @@ cmxClt = (function(cC) {
...
@@ -71,7 +71,7 @@ cmxClt = (function(cC) {
// -> interaction elements (params, else default)
// -> interaction elements (params, else default)
var
emailId
,
duuidId
,
passId
,
pass2Id
,
captchaId
,
capcheckId
var
emailId
,
duuidId
,
passId
,
pass2Id
,
captchaId
,
capcheckId
console
.
info
(
'new AuthForm "'
+
auForm
.
id
+
'"[.type='
+
auForm
.
type
+
'] init params'
,
afParams
)
//
console.info('new AuthForm "'+auForm.id+'"[.type='+auForm.type+'] init params', afParams)
emailId
=
afParams
.
emailId
||
'email'
emailId
=
afParams
.
emailId
||
'email'
duuidId
=
afParams
.
duuidId
||
'doors_uid'
duuidId
=
afParams
.
duuidId
||
'doors_uid'
...
...
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