Fakultas Ilmu Komputer UI

Commit 68bb8ba2 authored by Usman Sidiq's avatar Usman Sidiq
Browse files

Merge branch 'dev-sidiq' into 'PBI-3-registrasi_login'

[REFACTOR] Fix google account didn't have a user name

See merge request !63
parents 2bdd05de ced7d50f
Pipeline #49594 passed with stages
in 11 minutes and 40 seconds
......@@ -30,10 +30,11 @@ def request_token(request):
status = 200
if google:
access_token = request.POST["access_token"]
name = request.POST["name"]
try:
user = User.objects.get(email=email)
except User.DoesNotExist:
user, status = _request_token_from_google(email, access_token)
user, status = _request_token_from_google(email, access_token, name)
else:
try:
user = authenticate(request, username=email, password=password)
......@@ -59,7 +60,7 @@ def request_token(request):
return JsonResponse(response, status=400)
@csrf_exempt
def _request_token_from_google(email, access_token):
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)
data = json.loads(req.text)
......@@ -72,6 +73,7 @@ def _request_token_from_google(email, access_token):
user.password = make_password(BaseUserManager().make_random_password())
user.email = email
user.is_active = True
user.last_name = name
user.save()
random_generated_phone_number = 'x'.join([str(random.randint(0, 9)) for i in range(8)])
BisaGoUser.objects.create(user=user, phone_number=random_generated_phone_number)
......
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