From 3308353070c8b59afd29d1b8d30cc7d089ecfa77 Mon Sep 17 00:00:00 2001 From: Eduardo Robles Date: Fri, 22 Apr 2022 07:25:54 +0200 Subject: [PATCH] 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 --- authapi/api/fixtures/saas.json | 9 +++++++++ authapi/authmethods/m_emailpwd.py | 1 - authapi/authmethods/utils.py | 16 +--------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/authapi/api/fixtures/saas.json b/authapi/api/fixtures/saas.json index 9b651c0c..63f2a7c7 100644 --- a/authapi/api/fixtures/saas.json +++ b/authapi/api/fixtures/saas.json @@ -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, diff --git a/authapi/authmethods/m_emailpwd.py b/authapi/authmethods/m_emailpwd.py index c8560dd1..ecd65174 100644 --- a/authapi/authmethods/m_emailpwd.py +++ b/authapi/authmethods/m_emailpwd.py @@ -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') diff --git a/authapi/authmethods/utils.py b/authapi/authmethods/utils.py index ad2a5b61..3c3adb67 100644 --- a/authapi/authmethods/utils.py +++ b/authapi/authmethods/utils.py @@ -771,20 +771,6 @@ 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: @@ -975,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: