-
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.
Merge pull request #9 from fathonidf/development
tutorial 8 selesai
- Loading branch information
Showing
15 changed files
with
113 additions
and
8 deletions.
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 login, logout | ||
|
||
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!" | ||
}, 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
Binary file not shown.
Binary file not shown.
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