# Path: account/conf.py
# def load_path_attr(path):
#     def configure_hookset(self, value):
# class AccountAppConf(AppConf):
#     OPEN_SIGNUP = True
#     LOGIN_URL = "account_login"
#     LOGOUT_URL = "account_logout"
#     SIGNUP_REDIRECT_URL = "/"
#     LOGIN_REDIRECT_URL = "/"
#     LOGOUT_REDIRECT_URL = "/"
#     PASSWORD_CHANGE_REDIRECT_URL = "account_password"
#     PASSWORD_RESET_REDIRECT_URL = "account_login"
#     PASSWORD_RESET_TOKEN_URL = "account_password_reset_token"
#     PASSWORD_EXPIRY = 0
#     PASSWORD_USE_HISTORY = False
#     PASSWORD_STRIP = True
#     REMEMBER_ME_EXPIRY = 60 * 60 * 24 * 365 * 10
#     USER_DISPLAY = lambda user: user.username  # noqa
#     CREATE_ON_SAVE = True
#     EMAIL_UNIQUE = True
#     EMAIL_CONFIRMATION_REQUIRED = False
#     EMAIL_CONFIRMATION_EMAIL = True
#     EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
#     EMAIL_CONFIRMATION_AUTO_LOGIN = False
#     EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
#     EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
#     EMAIL_CONFIRMATION_URL = "account_confirm_email"
#     SETTINGS_REDIRECT_URL = "account_settings"
#     NOTIFY_ON_PASSWORD_CHANGE = True
#     DELETION_EXPUNGE_HOURS = 48
#     DEFAULT_HTTP_PROTOCOL = "https"
#     HOOKSET = "account.hooks.AccountDefaultHookSet"
#     TIMEZONES = TIMEZONES
#     LANGUAGES = LANGUAGES
# 
# Path: account/models.py
# class PasswordHistory(models.Model):
#     """
#     Contains single password history for user.
#     """
#     class Meta:
#         verbose_name = _("password history")
#         verbose_name_plural = _("password histories")
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="password_history", on_delete=models.CASCADE)
#     password = models.CharField(max_length=255)  # encrypted password
#     timestamp = models.DateTimeField(default=timezone.now)  # password creation time


import datetime
import functools
import pytz
from urllib.parse import urlparse, urlunparse
from django.contrib.auth import get_user_model
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponseRedirect, QueryDict
from django.urls import NoReverseMatch, reverse
from django.utils.encoding import force_str
from account.conf import settings
from .models import PasswordHistory
            raise
    url_bits = list(urlparse(force_str(login_url)))
    if redirect_field_name:
        querystring = QueryDict(url_bits[4], mutable=True)
        querystring[redirect_field_name] = next_url
        url_bits[4] = querystring.urlencode(safe="/")
    return HttpResponseRedirect(urlunparse(url_bits))


def get_form_data(form, field_name, default=None):
    if form.prefix:
        key = "-".join([form.prefix, field_name])
    else:
        key = field_name
    return form.data.get(key, default)


# https://stackoverflow.com/a/70419609/6461688
def is_ajax(request):
    """
    Return True if the request was sent with XMLHttpRequest, False otherwise.
    """
    return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'


def check_password_expired(user):
    """
    Return True if password is expired and system is using
    password expiration, False otherwise.
    """

# Path: account/conf.py
# def load_path_attr(path):
#     def configure_hookset(self, value):
# class AccountAppConf(AppConf):
#     OPEN_SIGNUP = True
#     LOGIN_URL = "account_login"
#     LOGOUT_URL = "account_logout"
#     SIGNUP_REDIRECT_URL = "/"
#     LOGIN_REDIRECT_URL = "/"
#     LOGOUT_REDIRECT_URL = "/"
#     PASSWORD_CHANGE_REDIRECT_URL = "account_password"
#     PASSWORD_RESET_REDIRECT_URL = "account_login"
#     PASSWORD_RESET_TOKEN_URL = "account_password_reset_token"
#     PASSWORD_EXPIRY = 0
#     PASSWORD_USE_HISTORY = False
#     PASSWORD_STRIP = True
#     REMEMBER_ME_EXPIRY = 60 * 60 * 24 * 365 * 10
#     USER_DISPLAY = lambda user: user.username  # noqa
#     CREATE_ON_SAVE = True
#     EMAIL_UNIQUE = True
#     EMAIL_CONFIRMATION_REQUIRED = False
#     EMAIL_CONFIRMATION_EMAIL = True
#     EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
#     EMAIL_CONFIRMATION_AUTO_LOGIN = False
#     EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "account_login"
#     EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
#     EMAIL_CONFIRMATION_URL = "account_confirm_email"
#     SETTINGS_REDIRECT_URL = "account_settings"
#     NOTIFY_ON_PASSWORD_CHANGE = True
#     DELETION_EXPUNGE_HOURS = 48
#     DEFAULT_HTTP_PROTOCOL = "https"
#     HOOKSET = "account.hooks.AccountDefaultHookSet"
#     TIMEZONES = TIMEZONES
#     LANGUAGES = LANGUAGES
# 
# Path: account/models.py
# class PasswordHistory(models.Model):
#     """
#     Contains single password history for user.
#     """
#     class Meta:
#         verbose_name = _("password history")
#         verbose_name_plural = _("password histories")
# 
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="password_history", on_delete=models.CASCADE)
#     password = models.CharField(max_length=255)  # encrypted password
#     timestamp = models.DateTimeField(default=timezone.now)  # password creation time


# Path: account/utils.py
import datetime
import functools
import pytz
from urllib.parse import urlparse, urlunparse
from django.contrib.auth import get_user_model
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponseRedirect, QueryDict
from django.urls import NoReverseMatch, reverse
from django.utils.encoding import force_str
from account.conf import settings
from .models import PasswordHistory

            raise
    url_bits = list(urlparse(force_str(login_url)))
    if redirect_field_name:
        querystring = QueryDict(url_bits[4], mutable=True)
        querystring[redirect_field_name] = next_url
        url_bits[4] = querystring.urlencode(safe="/")
    return HttpResponseRedirect(urlunparse(url_bits))


def get_form_data(form, field_name, default=None):
    if form.prefix:
        key = "-".join([form.prefix, field_name])
    else:
        key = field_name
    return form.data.get(key, default)


# https://stackoverflow.com/a/70419609/6461688
def is_ajax(request):
    """
    Return True if the request was sent with XMLHttpRequest, False otherwise.
    """
    return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'


def check_password_expired(user):
    """
    Return True if password is expired and system is using
    password expiration, False otherwise.
    """

    if not settings.ACCOUNT_PASSWORD_USE_HISTORY: