-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
145 changed files
with
30,791 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthenticationConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'authentication' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from authentication.views import * | ||
|
||
app_name = 'authentication' | ||
|
||
urlpatterns = [ | ||
path('login/', login, name='login'), | ||
path('logout/', logout, name='logout'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.shortcuts import render | ||
from django.contrib.auth import authenticate, login as auth_login | ||
from django.http import JsonResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.contrib.auth import logout as auth_logout | ||
|
||
@csrf_exempt | ||
def login(request): | ||
username = request.POST['username'] | ||
password = request.POST['password'] | ||
user = authenticate(username=username, password=password) | ||
if user is not None: | ||
if user.is_active: | ||
auth_login(request, user) | ||
# Status login sukses. | ||
return JsonResponse({ | ||
"username": user.username, | ||
"status": True, | ||
"message": "Login sukses!" | ||
# Tambahkan data lainnya jika ingin mengirim data ke Flutter. | ||
}, status=200) | ||
else: | ||
return JsonResponse({ | ||
"status": False, | ||
"message": "Login gagal, akun dinonaktifkan." | ||
}, status=401) | ||
|
||
else: | ||
return JsonResponse({ | ||
"status": False, | ||
"message": "Login gagal, periksa kembali email atau kata sandi." | ||
}, status=401) | ||
|
||
@csrf_exempt | ||
def logout(request): | ||
username = request.user.username | ||
|
||
try: | ||
auth_logout(request) | ||
return JsonResponse({ | ||
"username": username, | ||
"status": True, | ||
"message": "Logout berhasil!" | ||
}, status=200) | ||
except: | ||
return JsonResponse({ | ||
"status": False, | ||
"message": "Logout gagal." | ||
}, status=401) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ psycopg2-binary | |
requests | ||
urllib3 | ||
django-environ | ||
whitenoise | ||
whitenoise | ||
django-cors-headers |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.