<commit_before>import logging

from django.contrib import messages
from django.contrib.auth import get_user_model

from django.contrib.auth.decorators import login_required
from django.contrib.auth.signals import user_logged_in

from django.contrib.auth.tokens import default_token_generator
from django.dispatch import receiver
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.http import urlsafe_base64_decode
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_post_parameters

from two_factor import views as tfv
from two_factor.utils import default_device
from django_otp import devices_for_user
from django.shortcuts import redirect

from useraudit.models import UserDeactivation
from useraudit.password_expiry import is_password_expired

from registry.patients.models import Patient, ParentGuardian

from rdrf.auth import can_user_self_unlock, is_user_privileged


from .forms import UserVerificationForm, ReactivateAccountForm


logger = logging.getLogger(__name__)


@receiver(user_logged_in)
def user_login_callback(sender, request=None, user=None, **kwargs):
    if is_user_privileged(
            user) and not user.require_2_fact_auth and default_device(user) is None:
        link = ('<a href="%(url)s" class="alert-link">' + _('click here') +
                '</a>') % {'url': reverse('two_factor:setup')}
        msg = mark_safe(
            _('We strongly recommend that you protect your account with Two-Factor authentication. '
              'Please %(link)s to set it up.') % {'link': link})

        if msg not in [m.message for m in messages.get_messages(request)]:
            messages.info(request, msg)


# Customised Two Factor views


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class QRGeneratorView(tfv.core.QRGeneratorView):
    session_key_name = 'two_fact_auth_key'


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class SetupView(tfv.core.SetupView):
    session_key_name = 'two_fact_auth_key'


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class DisableView(tfv.profile.DisableView):
    def form_valid(self, form):
        for device in devices_for_user(self.request.user):
            device.delete()

        return redirect(self.request.POST['redirect_url'])


# Doesn't need csrf_protect since no-one can guess the URL<commit_msg>trying to fix branch issue - added dummy comment (rdrf-ccg #988)<commit_after>import logging

from django.contrib import messages
from django.contrib.auth import get_user_model

from django.contrib.auth.decorators import login_required
from django.contrib.auth.signals import user_logged_in

from django.contrib.auth.tokens import default_token_generator
from django.dispatch import receiver
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.http import urlsafe_base64_decode
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_post_parameters

from two_factor import views as tfv
from two_factor.utils import default_device
from django_otp import devices_for_user
from django.shortcuts import redirect

from useraudit.models import UserDeactivation
from useraudit.password_expiry import is_password_expired

from registry.patients.models import Patient, ParentGuardian

from rdrf.auth import can_user_self_unlock, is_user_privileged


from .forms import UserVerificationForm, ReactivateAccountForm


logger = logging.getLogger(__name__)


@receiver(user_logged_in)
def user_login_callback(sender, request=None, user=None, **kwargs):
    if is_user_privileged(
            user) and not user.require_2_fact_auth and default_device(user) is None:
        link = ('<a href="%(url)s" class="alert-link">' + _('click here') +
                '</a>') % {'url': reverse('two_factor:setup')}
        msg = mark_safe(
            _('We strongly recommend that you protect your account with Two-Factor authentication. '
              'Please %(link)s to set it up.') % {'link': link})

        if msg not in [m.message for m in messages.get_messages(request)]:
            messages.info(request, msg)

#dummy code

# Customised Two Factor views


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class QRGeneratorView(tfv.core.QRGeneratorView):
    session_key_name = 'two_fact_auth_key'


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class SetupView(tfv.core.SetupView):
    session_key_name = 'two_fact_auth_key'


@tfv.utils.class_view_decorator(never_cache)
@tfv.utils.class_view_decorator(login_required)
class DisableView(tfv.profile.DisableView):
    def form_valid(self, form):
        for device in devices_for_user(self.request.user):
            device.delete()

        return redirect(self.request.POST['redirect_url'])


# Doesn't need csrf_protect since no-one can guess the URL
{'fraction_non_alphanumeric': 0.07921153495163351, 'fraction_numerical': 0.001642635517430188, 'mean_word_length': 5.041896361631753, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2324079', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1607, 'n_words': 414}