-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy ulang untuk integrasi dengan flutter
- Loading branch information
Showing
12 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
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
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,48 @@ | ||
from django.shortcuts import render | ||
from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout | ||
from django.http import JsonResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
@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