This file contains hidden or 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
import { pgTable, serial, text, varchar, integer } from 'drizzle-orm/pg-core'; | |
//#region Users | |
export const user = pgTable("user", { | |
id: serial('id').primaryKey(), | |
email: varchar("email", { length: 255 }).unique().notNull(), | |
password: varchar("password", { length: 255 }).notNull() | |
}); |
This file contains hidden or 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
useEffect(() => { | |
const checkClickedOutside = (ev: MouseEvent) => { | |
console.log("Click"); | |
if ( | |
isDropdownOpen && | |
ref.current && | |
!ref.current.contains(ev.target as Node) | |
) { | |
setDropdownOpen(false); | |
} |
This file contains hidden or 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
import json | |
from django.urls import include, path, reverse | |
from rest_framework import status | |
from rest_framework.test import APITestCase, APIClient, URLPatternsTestCase | |
from .models import User | |
# Create your tests here. | |
class UserTest(APITestCase, URLPatternsTestCase): | |
""" Test module for User """ |
This file contains hidden or 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
from django.contrib import admin | |
from django.urls import path, include | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('api/auth/', include('api.urls')) | |
] |
This file contains hidden or 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
from django.urls import path | |
from rest_framework_simplejwt import views as jwt_views | |
from .views import ( | |
UserRegistrationView, | |
UserLoginView, | |
UserListView | |
) | |
urlpatterns = [ |
This file contains hidden or 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
class UserListView(APIView): | |
serializer_class = UserListSerializer | |
permission_classes = (IsAuthenticated,) | |
def get(self, request): | |
user = request.user | |
if user.role != 1: | |
response = { | |
'success': False, | |
'status_code': status.HTTP_403_FORBIDDEN, |
This file contains hidden or 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
class AuthUserLoginView(APIView): | |
serializer_class = UserLoginSerializer | |
permission_classes = (AllowAny, ) | |
def post(self, request): | |
serializer = self.serializer_class(data=request.data) | |
valid = serializer.is_valid(raise_exception=True) | |
if valid: | |
status_code = status.HTTP_200_OK |
This file contains hidden or 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
from rest_framework import status | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
from rest_framework.permissions import AllowAny, IsAuthenticated | |
from .serializers import ( | |
UserRegistrationSerializer, | |
UserLoginSerializer, | |
UserListSerializer | |
) |
This file contains hidden or 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
class UserListSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = AuthUser | |
fields = ( | |
'email', | |
'role' | |
) |
This file contains hidden or 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
from rest_framework import serializers | |
from rest_framework_simplejwt.tokens import RefreshToken | |
class UserLoginSerializer(serializers.Serializer): | |
email = serializers.EmailField() | |
password = serializers.CharField(max_length=128, write_only=True) | |
access = serializers.CharField(read_only=True) | |
refresh = serializers.CharField(read_only=True) | |
role = serializers.CharField(read_only=True) |
NewerOlder