32 lines
885 B
Python
32 lines
885 B
Python
|
|
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),
|
||
|
|
}
|