(request)
return redirect("/")
Allows superusers to log in as a regular user to troubleshoot problems.
Allows superusers to log in as a regular user to troubleshoot problems.
Allows superusers to log in as a regular user to troubleshoot problems .
def debug_user(request):
    """
    Allows superusers to log in as a regular user to troubleshoot problems.
    """

    if not settings.DEBUG_USERS:
        messages.error(request, "Can only use when in debug mode.")
        return redirect("/")

    target = request.GET.get("uid", "")
    profile = Profile.objects.filter(uid=target).first()

    if not profile:
        messages.error(request, "User does not exists.")
        return redirect("/")

    user = profile.user
    login(request, user, backend="django.contrib.auth.backends.ModelBackend")

    logger.info(f"""uid={request.user.profile.uid} impersonated
                    uid={profile.uid}.""")

    return redirect("/")
def debug_user ( request ) : if not settings . DEBUG_USERS : messages . error ( request , "Can only use when in debug mode." ) return redirect ( "/" ) target = request . GET . get ( "uid" , "" ) profile = Profile . objects . filter ( uid = target ) . first ( ) if not profile : messages . error ( request , "User does not exists." ) return redirect ( "/" ) user = profile . user login ( request , user , backend = "django.contrib.auth.backends.ModelBackend" ) logger . info ( f"""uid={request.user.profile.uid} impersonated
                    uid={profile.uid}.""" ) return redirect ( "/" )