o
    mi                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZm	Z	 G dd deZ
G dd	 d	ejZG d
d dejZG dd dejZG dd dejZG dd dejZdS )    )EmailOrPhoneNoAuthBackend)serializers)TokenObtainPairSerializer)
exceptions)User
Permissionc                   @   s   e Zd Zdd ZdS )UserLoginSerializerc                 C   st   t j|dd |dd d}|r5| |}t|d| jd idj}i |}t|j|d< t||d< |S t	
d)	Nphone_nopassword)emailr
   request)contextaccessrefreshz2No active account found with the given credentials)r   authenticateget	get_tokenUserSerializerr   datastraccess_tokenr   NotFound)selfattrsuserr   Z	user_datar    r   L/var/www/html/kuke-dev/django-kuke/apps/user/serializers/user_serializers.pyvalidate   s   

zUserLoginSerializer.validateN)__name__
__module____qualname__r   r   r   r   r   r          r   c                   @   s*   e Zd ZejddddZG dd dZdS )r   z	role.nameT)source	read_only
allow_nullc                   @      e Zd ZeZdZeZdS )zUserSerializer.Meta)id
first_name	last_namer   r	   profile_picprofile_pic_thumb	role_nameNr   r   r    r   modelfieldsread_only_fieldsr   r   r   r   Meta!       r0   N)r   r   r    r   	CharFieldr+   r0   r   r   r   r   r      s    r   c                   @   s   e Zd ZG dd dZdS )UserDetailSerializerc                   @   r%   )zUserDetailSerializer.Meta)r&   r'   r(   r   r	   r)   r*   Nr,   r   r   r   r   r0   )   r1   r0   N)r   r   r    r0   r   r   r   r   r3   '   s    r3   c                   @   s   e Zd Ze ZdS )UserPermissionAPISerializerN)r   r   r    r   r2   permissionsr   r   r   r   r4   0   r!   r4   c                       s*   e Zd ZG dd dZ fddZ  ZS )UserEditProfileSerializerc                   @   s   e Zd ZeZdZdgZdS )zUserEditProfileSerializer.Meta)r'   r(   r	   r)   r*   r*   Nr,   r   r   r   r   r0   6   s    
r0   c                    s0   | d}|r| dr|d |d< t |S )Nr)   r*   )r   superr   )r   r   r)   	__class__r   r   r   <   s
   

z"UserEditProfileSerializer.validate)r   r   r    r0   r   __classcell__r   r   r8   r   r6   4   s    r6   c                   @   s8   e Zd ZejddZejddZejddZdd ZdS )ChangePasswordSerializerT)requiredc                 C   sf   | j d j}|d}|d}|d}||std||kr(td||kr1td|S )Nr   current_passwordnew_passwordconfirm_new_passwordzCurrent password is incorrect.z9New password must be different from the current password.z1New password and confirm new password must match.)r   r   r   check_passwordr   ValidationError)r   r   r   r=   r>   r?   r   r   r   r   K   s   






z!ChangePasswordSerializer.validateN)	r   r   r    r   r2   r=   r>   r?   r   r   r   r   r   r;   F   s
    r;   N)Z!apps.user.authentication_backendsr   rest_frameworkr   Z$rest_framework_simplejwt.serializersr   r   apps.user.modelsr   r   r   ModelSerializerr   r3   
Serializerr4   r6   r;   r   r   r   r   <module>   s    		