mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +00:00
refactor: Update project settings, URL configurations, client views, and remove requirements.txt.
This commit is contained in:
Binary file not shown.
Binary file not shown.
5
gestaoRaul/login/api_views.py
Normal file
5
gestaoRaul/login/api_views.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from .serializers import MyTokenObtainPairSerializer
|
||||
|
||||
class MyTokenObtainPairView(TokenObtainPairView):
|
||||
serializer_class = MyTokenObtainPairSerializer
|
||||
27
gestaoRaul/login/serializers.py
Normal file
27
gestaoRaul/login/serializers.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
|
||||
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
|
||||
@classmethod
|
||||
def get_token(cls, user):
|
||||
token = super().get_token(user)
|
||||
|
||||
# Adicione campos personalizados ao token (payload) se desejar
|
||||
token['username'] = user.username
|
||||
token['groups'] = list(user.groups.values_list('name', flat=True))
|
||||
|
||||
return token
|
||||
|
||||
def validate(self, attrs):
|
||||
data = super().validate(attrs)
|
||||
|
||||
# Adicione informações do usuário na resposta do JSON
|
||||
data['user'] = {
|
||||
'id': self.user.id,
|
||||
'username': self.user.username,
|
||||
'email': self.user.email,
|
||||
'first_name': self.user.first_name,
|
||||
'last_name': self.user.last_name,
|
||||
'groups': list(self.user.groups.values_list('name', flat=True))
|
||||
}
|
||||
|
||||
return data
|
||||
Reference in New Issue
Block a user