Automatically logs in a user based on a signed PK of a user object. The
    signature should be generated with the `login` management command.

    The signature will only work for 60 seconds.

def login(request, signature):
    """
    Automatically logs in a user based on a signed PK of a user object. The
    signature should be generated with the `login` management command.

    The signature will only work for 60 seconds.
    """
    signer = TimestampSigner()
    try:
        pk = signer.unsign(signature, max_age=MAX_AGE_OF_SIGNATURE_IN_SECONDS)
    except (BadSignature, SignatureExpired) as e:
        return HttpResponseForbidden("Can't log you in")

    user = get_object_or_404(get_user_model(), pk=pk)
    # we *have* to set the backend for this user, so we just use the first one
    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    django_login(request, user)

    return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)