def reason_display(self): from authentication.errors import reason_choices, old_reason_choices reason = reason_choices.get(self.reason) if reason: return reason reason = old_reason_choices.get(self.reason, self.reason) return reason
def authenticate(self, request, saml_user_data=None, **kwargs): log_prompt = "Process authenticate [SAML2AuthCodeBackend]: {}" logger.debug(log_prompt.format('Start')) if saml_user_data is None: logger.error(log_prompt.format('saml_user_data is missing')) return None logger.debug(log_prompt.format('saml data, {}'.format(saml_user_data))) username = saml_user_data.get('username') if not username: logger.debug(log_prompt.format('username is missing')) return None user, created = self.get_or_create_from_saml_data( request, **saml_user_data) if self.user_can_authenticate(user): logger.debug(log_prompt.format('SAML2 user login success')) saml2_user_authenticated.send(sender=self, request=request, user=user, created=created) return user else: logger.debug(log_prompt.format('SAML2 user login failed')) saml2_user_authentication_failed.send( sender=self, request=request, username=username, reason=reason_choices.get(reason_user_invalid)) return None