<commit_before>from django.conf import settings

from django_browserid.auth import BrowserIDBackend


class CustomBackend(BrowserIDBackend):
  def filter_users_by_email(self, email):
    # Check for existence of email address in a list of two-tuples
    is_admin = [i for i, v in enumerate(settings.PRIVILEGED_USERS) if v[0] == email]

    return is_admin<commit_msg>Fix issues when attempting to log in. Override BrowserIDBackend.authenticate().<commit_after>from django.conf import settings
from django.contrib.auth.models import User

from django_browserid.auth import BrowserIDBackend
from django_browserid.base import get_audience

from mozcal.base.utils import get_or_create_instance


class BrowserIDBackend(BrowserIDBackend):
  def authenticate(self, assertion=None, audience=None, request=None, **kwargs):
    if audience is None and request:
      audience = get_audience(request)

    if audience is None or assertion is None:
      return None

    verifier = self.get_verifier()
    result = verifier.verify(assertion, audience, **kwargs)

    if result.email in settings.PRIVILEGED_USERS:
      user, created = get_or_create_instance(User, username='admin')

      if created:
        user.save()

      return user
    else:
      return None
{'fraction_non_alphanumeric': 0.07080350039777247, 'fraction_numerical': 0.0007955449482895784, 'mean_word_length': 4.353191489361702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4583269', 'n_tokens_mistral': 369, 'n_tokens_neox': 361, 'n_words': 111}