From d03ff40bc8e471547219323d812ccb3315d724e2 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 26 Jul 2021 16:36:30 +0200 Subject: [PATCH 1/3] auth_fc: refactor missing required attributes check (#55836) --- src/authentic2_auth_fc/views.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/authentic2_auth_fc/views.py b/src/authentic2_auth_fc/views.py index f7c65c55..11e77b49 100644 --- a/src/authentic2_auth_fc/views.py +++ b/src/authentic2_auth_fc/views.py @@ -347,14 +347,8 @@ class LoginOrLinkView(View): # set session expiration policy to EXPIRE_AT_BROWSER_CLOSE request.session.set_expiry(0) - # redirect to account edit page if any required attribute is missing - name_to_label = dict(a2_models.Attribute.objects.filter(required=True).values_list('name', 'label')) - required = list(a2_app_settings.A2_REGISTRATION_REQUIRED_FIELDS) + list(name_to_label) - missing = [] - for attr_name in set(required): - value = getattr(user, attr_name, None) or getattr(user.attributes, attr_name, None) - if value in [None, '']: - missing.append(name_to_label[attr_name]) + # redirect to account edit page if any required attribute is not filled + missing = self.missing_required_attributes(user) if missing: messages.warning( request, @@ -363,6 +357,17 @@ class LoginOrLinkView(View): return utils_misc.redirect(request, 'profile_edit', params={'next': self.next_url}) return self.redirect() + def missing_required_attributes(self, user): + '''Compute if user has not filled some required attributes.''' + name_to_label = dict(a2_models.Attribute.objects.filter(required=True).values_list('name', 'label')) + required = list(a2_app_settings.A2_REGISTRATION_REQUIRED_FIELDS) + list(name_to_label) + missing = [] + for attr_name in set(required): + value = getattr(user, attr_name, None) or getattr(user.attributes, attr_name, None) + if value in [None, '']: + missing.append(name_to_label[attr_name]) + return missing + def create_account(self, request, sub, token, user_info): email = user_info.get('email') -- 2.32.0.rc0