def token_new(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') if username and password: user = authenticate(username=username, password=password) if user: TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False) if TOKEN_CHECK_ACTIVE_USER and not user.is_active: return JSONError("User account is disabled.") data = { 'token': token_generator.make_token(user), 'user': user.pk, } return JSONResponse(data) else: return JSONError("Unable to log you in, please try again.") else: return JSONError( "Must include 'username' and 'password' as POST parameters.") else: return JSONError("Must access via a POST request.")
def token(request, token, user): data = {} try: user = User.objects.get(pk=user) except User.DoesNotExist: return JSONError("User does not exist.") if token_generator.check_token(user, token): return JSONResponse({}) else: return JSONError("Token did not match user.")
def token(request, token, user): try: user = User.objects.get(pk=user) except User.DoesNotExist: return JSONError("User does not exist.") TOKEN_CHECK_ACTIVE_USER = getattr(settings, "TOKEN_CHECK_ACTIVE_USER", False) if TOKEN_CHECK_ACTIVE_USER and not user.is_active: return JSONError("User account is disabled.") if token_generator.check_token(user, token): return JSONResponse({}) else: return JSONError("Token did not match user.")
def token(request): token = request.REQUEST.get('token') user, token = token.split('|') try: user = int(user) except ValueError: return JSONError("Inavalid token format.") try: user = User.objects.get(pk=user) except User.DoesNotExist: return JSONError("User does not exist.") if token_generator.check_token(user, token): return JSONResponse({}) else: return JSONError("Token did not match user.")
def token_new(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') if username and password: user = authenticate(username=username, password=password) if user: data = { 'token': token_generator.make_token(user), } return JSONResponse(data) else: return JSONError("Unable to log you in, please try again.") else: return JSONError( "Must include 'username' and 'password' as POST parameters.") else: return JSONError("Must access via a POST request.")