def METHOD_NAME(request):
    """
    Handle login
    """
    # Only allow users to access login page if they are not logged in
    if not request.user.is_anonymous:
        return redirect("user:profile")
    # Handle form
    if request.method == "POST" and "login-submit" in request.POST:
        # Create login form bound to request data
        form = LoginForm(request.POST)
        # Validate the form
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            # Authenticate
            user = authenticate(request, username=username, password=password)
            # If not authenticated, user will be None
            if user is not None:
                # The password has been verified for the user
                if user.is_active:
                    # Check for multi factor authentication
                    mfa_response = has_mfa(request, user.username)
                    if mfa_response:
                        return mfa_response
                    return log_user_in(request, user)
                else:
                    # The password is valid, but the user account has been disabled
                    # Return a disabled account 'error' message
                    messages.error(
                        request,
                        "Sorry, but your account has been disabled. Please contact the site "
                        "administrator for more details.",
                    )
            else:
                # User was not authenticated, return errors
                messages.warning(
                    request,
                    "Whoops! We were not able to log you in. Please check your username and "
                    "password and try again.",
                )
    else:
        # Create new empty login form
        form = LoginForm()
    # Determine if signup is disabled or not
    signup_enabled = (
        settings.ENABLE_OPEN_SIGNUP
        if hasattr(settings, "ENABLE_OPEN_SIGNUP")
        else False
    )
    context = {"form": form, "signup_enabled": signup_enabled}
    template = get_custom_template(
        "Login Page Template", "tethys_portal/accounts/login.html"
    )
    return render(request, template, context)