Fakultas Ilmu Komputer UI

Commit 82130f33 authored by Fakhira Devina's avatar Fakhira Devina
Browse files

Merge branch 'dev-rafif' into 'PBI-2-deployment'

Add Global Proxies variable and fix error Response

See merge request !2
parents 7edee322 13176b85
Pipeline #64459 failed with stages
in 11 minutes and 8 seconds
...@@ -16,7 +16,7 @@ from django.contrib.auth import authenticate ...@@ -16,7 +16,7 @@ from django.contrib.auth import authenticate
from django.contrib.auth.base_user import BaseUserManager from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.hashers import make_password from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User from django.contrib.auth.models import User
from pplbackend.settings import GOOGLE_OAUTH2_CLIENT_ID, GOOGLE_OAUTH2_CLIENT_SECRET from django.conf import settings
from registrasi.models import BisaGoUser from registrasi.models import BisaGoUser
...@@ -42,7 +42,7 @@ def request_token(request): ...@@ -42,7 +42,7 @@ def request_token(request):
response["response"] = "User not exist" response["response"] = "User not exist"
return JsonResponse(response, status=404) return JsonResponse(response, status=404)
if status != 200: if status != 200:
return response return status
if user is not None: if user is not None:
if user.is_active: if user.is_active:
#print("user active") #print("user active")
...@@ -62,7 +62,7 @@ def request_token(request): ...@@ -62,7 +62,7 @@ def request_token(request):
@csrf_exempt @csrf_exempt
def _request_token_from_google(email, access_token, name): def _request_token_from_google(email, access_token, name):
payload = {'access_token': access_token} # validate the 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=settings.PROXIES)
data = json.loads(req.text) data = json.loads(req.text)
if 'error' in data: if 'error' in data:
content = {'message': 'wrong google token / this google token is already expired.'} content = {'message': 'wrong google token / this google token is already expired.'}
...@@ -83,7 +83,7 @@ def _request_token_from_google(email, access_token, name): ...@@ -83,7 +83,7 @@ def _request_token_from_google(email, access_token, name):
@csrf_exempt @csrf_exempt
def validate_google_token(email, access_token): def validate_google_token(email, access_token):
payload = {'access_token': access_token} # validate the 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=settings.PROXIES)
data = json.loads(req.text) data = json.loads(req.text)
if 'error' in data: if 'error' in data:
content = {'message': 'wrong google token / this google token is already expired.'} content = {'message': 'wrong google token / this google token is already expired.'}
......
...@@ -223,3 +223,11 @@ SIMPLE_JWT = { ...@@ -223,3 +223,11 @@ SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=1), 'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=90), 'REFRESH_TOKEN_LIFETIME': timedelta(days=90),
} }
http_proxy = os.environ.get('http_proxy', '')
https_proxy = os.environ.get('https_proxy', '')
PROXIES ={
"http" : http_proxy,
"https" : https_proxy
}
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