示例#1
0
    def _handle_duplicate_email_username(self, request, data):
        # pylint: disable=no-member
        # TODO Verify whether this check is needed here - it may be duplicated in user_api.
        email = data.get('email')
        username = data.get('username')
        errors = {}

        # TODO: remove the is_authn_mfe check and use the new error message as default after redesign
        is_authn_mfe = data.get('is_authn_mfe', False)

        error_code = 'duplicate'
        if email is not None and email_exists_or_retired(email):
            error_code += '-email'
            error_message = accounts_settings.AUTHN_EMAIL_CONFLICT_MSG if is_authn_mfe else (
                accounts_settings.EMAIL_CONFLICT_MSG.format(email_address=email)
            )
            errors['email'] = [{'user_message': error_message}]

        if username is not None and username_exists_or_retired(username):
            error_code += '-username'
            error_message = accounts_settings.AUTHN_USERNAME_CONFLICT_MSG if is_authn_mfe else (
                accounts_settings.USERNAME_CONFLICT_MSG.format(username=username)
            )
            errors['username'] = [{'user_message': error_message}]
            errors['username_suggestions'] = generate_username_suggestions(username)

        if errors:
            return self._create_response(request, errors, status_code=409, error_code=error_code)
示例#2
0
 def username_handler(self, request):
     """ Validates whether the username is valid. """
     username = request.data.get('username')
     invalid_username_error = get_username_validation_error(username)
     username_exists_error = get_username_existence_validation_error(username, self.api_version)
     if username_exists_error:
         self.username_suggestions = generate_username_suggestions(username)
     # We prefer seeing for invalidity first.
     # Some invalid usernames (like for superusers) may exist.
     return invalid_username_error or username_exists_error
示例#3
0
 def name_handler(self, request):
     """ Validates whether fullname is valid """
     name = request.data.get('name')
     self.username_suggestions = generate_username_suggestions(name)
     return get_name_validation_error(name)