Skip to content

Commit

Permalink
fixing adding census to user-and-password users (#200)
Browse files Browse the repository at this point in the history
* fixing adding census to user-and-password users (#195)

* fixing setting users email in `edit_user` function  (#197)

* fixing edit password. the refactor on explicit authentication made it redundant some code and a previous fix didn't account for that

* trying to fix saas unit test
  • Loading branch information
edulix committed Apr 25, 2022
1 parent 9063f20 commit 84f9b04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
9 changes: 9 additions & 0 deletions authapi/api/fixtures/saas.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
"fields": {
"census": "open",
"extra_fields": [
{
"name":"tlf",
"min":2,
"unique":true,
"max":200,
"type":"tlf",
"required":true,
"required_on_authentication":true
},
{
"name":"Email",
"min":2,
Expand Down
1 change: 0 additions & 1 deletion authapi/authmethods/m_emailpwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def authenticate_error(self, error, req, ae):
def authenticate(self, auth_event, request, mode='authenticate'):
d = {'status': 'ok'}
req = json.loads(request.body.decode('utf-8'))
password = req.get('password', '')

msg = ""
msg += check_fields_in_request(req, auth_event, 'authenticate')
Expand Down
28 changes: 11 additions & 17 deletions authapi/authmethods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,22 +771,10 @@ def get_cannonical_tlf(tlf):


def edit_user(user, req, auth_event):
if auth_event.auth_method == 'user-and-password':
req.pop('username')
req.pop('password')
elif auth_event.auth_method == 'email-and-password':
req.pop('email')
req.pop('password')

if req.get('email'):
user.email = req.get('email')
req.pop('email')
if req.get('tlf'):
user.userdata.tlf = get_cannonical_tlf(req['tlf'])
req.pop('tlf')

if auth_event.extra_fields:
for extra in auth_event.extra_fields:
if extra.get('type') not in req:
continue
if extra.get('type') == 'email' and req.get(extra.get('name')):
user.email = req.get(extra.get('name'))
req.pop(extra.get('name'))
Expand Down Expand Up @@ -851,7 +839,10 @@ def get_trimmed_user_req(req, ae):

if ae.extra_fields:
for extra in ae.extra_fields:
if extra.get('type') in ['password', 'image']:
if (
extra.get('type') in ['password', 'image'] and
extra.get('name') in metadata
):
metadata.pop(extra.get('name'))

return metadata
Expand All @@ -865,7 +856,10 @@ def get_trimmed_user(user, ae):

if ae.extra_fields:
for extra in ae.extra_fields:
if extra.get('type') in ['password', 'image']:
if (
extra.get('type') in ['password', 'image'] and
extra.get('name') in metadata
):
metadata.pop(extra.get('name'))

if user.email:
Expand Down Expand Up @@ -967,7 +961,7 @@ def post_verify_fields_on_auth(user, req, auth_event):
for field in auth_event.extra_fields:
if not field.get('required_on_authentication'):
continue

# Raise exception if a required field is not provided.
# It will be catched by parent as an error.
if field.get('name') not in req:
Expand Down

0 comments on commit 84f9b04

Please sign in to comment.