Fakultas Ilmu Komputer UI

Commit c6cce0cd authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

[REFACTOR] Add proxy settings for request and fix error response

parent e98196d0
Pipeline #63963 failed with stages
in 6 minutes and 24 seconds
......@@ -16,7 +16,7 @@ from django.contrib.auth import authenticate
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
from pplbackend.settings import GOOGLE_OAUTH2_CLIENT_ID, GOOGLE_OAUTH2_CLIENT_SECRET
from pplbackend.settings import GOOGLE_OAUTH2_CLIENT_ID, GOOGLE_OAUTH2_CLIENT_SECRET, PROXIES
from registrasi.models import BisaGoUser
......@@ -42,7 +42,7 @@ def request_token(request):
response["response"] = "User not exist"
return JsonResponse(response, status=404)
if status != 200:
return response
return status
if user is not None:
if user.is_active:
#print("user active")
......@@ -62,7 +62,7 @@ def request_token(request):
@csrf_exempt
def _request_token_from_google(email, access_token, name):
payload = {'access_token': access_token} # validate the token
req = requests.get('https://www.googleapis.com/oauth2/v2/userinfo', params=payload)
req = requests.get('https://www.googleapis.com/oauth2/v2/userinfo', params=payload, proxies=PROXIES)
data = json.loads(req.text)
if 'error' in data:
content = {'message': 'wrong google token / this google token is already expired.'}
......@@ -83,7 +83,7 @@ def _request_token_from_google(email, access_token, name):
@csrf_exempt
def validate_google_token(email, access_token):
payload = {'access_token': access_token} # validate the token
req = requests.get('https://www.googleapis.com/oauth2/v2/userinfo', params=payload)
req = requests.get('https://www.googleapis.com/oauth2/v2/userinfo', params=payload, proxies=PROXIES)
data = json.loads(req.text)
if 'error' in data:
content = {'message': 'wrong google token / this google token is already expired.'}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment