-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/002-refactore-backend' of github.com:abbastoof…
…/transcendence into develop
- Loading branch information
Showing
24 changed files
with
1,682 additions
and
105 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
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
from django.db import models | ||
|
||
|
||
# Create your models here. | ||
class UserTokens(models.Model): | ||
username = models.CharField(unique=True) | ||
token_data = models.JSONField(null=True) | ||
|
||
def __str__(self): | ||
return self.username | ||
# from django.db import models |
22 changes: 22 additions & 0 deletions
22
Backend/auth_service/auth_service/user_auth/serializers.py
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,22 @@ | ||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer | ||
import asyncio | ||
|
||
class CustomTokenObtainPairSerializer(TokenObtainPairSerializer): | ||
@classmethod | ||
def get_token(cls, user) -> dict: | ||
|
||
""" | ||
Get token method to generate tokens for the user. | ||
This method overrides the get_token method of TokenObtainPairSerializer to generate tokens for the user. | ||
It generates the tokens for the user and returns the tokens. | ||
Args: | ||
user: The user object. | ||
Returns: | ||
dict: The dictionary containing the tokens. | ||
""" | ||
token = super().get_token(user) | ||
token["custom_claims"] = {"username": user.username, "password": user.password} | ||
return token |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# from django.contrib import admin | ||
from django.urls import path | ||
from rest_framework_simplejwt.views import TokenRefreshView | ||
from user_auth.views import CustomTokenObtainPairView | ||
from user_auth.views import CustomTokenObtainPairView, CustomTokenRefreshView | ||
|
||
urlpatterns = [ | ||
path("api/token/", CustomTokenObtainPairView.as_view(), name="token_obtain_pair"), | ||
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"), | ||
path("api/token/refresh/", CustomTokenRefreshView.as_view(), name="token_refresh"), | ||
] |
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
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
Oops, something went wrong.