adding
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from apps.account.models import User
|
||||
|
||||
|
||||
class UserSelector:
|
||||
@staticmethod
|
||||
def get_user_profile(user: User) -> dict:
|
||||
return {
|
||||
"id": user.id,
|
||||
"phone": user.phone,
|
||||
"name": user.name,
|
||||
"state": user.state,
|
||||
"created_at": user.created_at,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_tokens_for_user(user: User) -> dict:
|
||||
refresh = RefreshToken.for_user(user)
|
||||
return {
|
||||
"refresh": str(refresh),
|
||||
"access": str(refresh.access_token),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_token_response(user: User) -> dict:
|
||||
return {
|
||||
"message": "ورود با موفقیت انجام شد.",
|
||||
"tokens": UserSelector.get_tokens_for_user(user),
|
||||
"user": UserSelector.get_user_profile(user),
|
||||
}
|
||||
Reference in New Issue
Block a user