+
    3Ti%                       ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	 ^ RI
HtHt ^ RIHt ^ RIHtHtHt ]! 0 Rm4      tR	 R
 lt]! R.4      ]	! ].4      R 4       4       t]! R.4      ]	! ].4      R 4       4       t]! R.4      ]	! ].4      R 4       4       t]! R.4      ]	! ].4      R 4       4       t]! R.4      ]	! ].4      R 4       4       tR# )    )annotations)get_user_model)authenticate)Token)api_viewpermission_classes)AllowAnyIsAuthenticatedResponse)_check_bcrypt_password_fetch_legacy_user_normalize_role_stringc                   V ^8  d   QhRR/# )   returnbool )formats   "FE:/live-kit-agent/livekit_voicebot/backend/config\master_auth_views.py__annotate__r      s     9 9T 9    c                &    \        V 4      \        9   # )N)r   _MASTER_ROLES)roles   &r   _is_master_roler      s    !$'=88r   POSTc                	   V P                   P                  R4      ;'       g&    V P                   P                  R4      ;'       g    RP                  4       pV P                   P                  R4      ;'       g    RP                  4       pV'       d	   V'       g   \        RRRR/R	R
7      # \	        V4      pV'       Egi   \        4       pRp\        WVR7      pVe   TpMN VP                  P                  VR7      P                  4       pVe    \        V \        VRR4      VR7      pVe   TpVf   \        RRRR/RR
7      # \        VRR4      '       g%   \        VRR4      '       g   \        RRRR/RR
7      # \        P                  P                  VR7      w  r\        VRR4      '       d   RMRp\        RRRV	P                  RR\        \        VRR4      4      R\        \        VRR4      ;'       g    R4      R\        \        VRR4      ;'       g    R4      RVRR//4      # VP                  R4      ;'       g    RP                  4       pV'       d   \!        W,4      '       g   \        RRRR/RR
7      # \#        VP                  R4      4      p\%        V4      '       g   \        RRRR/RR
7      # \        4       p\        VP                  R4      ;'       g    VP                  R4      ;'       g    T4      R,          pVP                  P                  VR7      w  r^V'       d   VP'                  4        \        VP                  R4      ;'       g    R4      Vn        RVn        RVn        TP/                  . R!OV'       d   R.M. ,           R7       \        P                  P                  VR7      w  r\        RRRV	P                  RR\        VP                  R 4      ;'       g    VP0                  4      R\        VP                  R4      ;'       g    VP                  R4      ;'       g    R4      R\        VP                  R4      ;'       g    R4      RVRVP                  R4      //4      #   \         d    Rp EL|i ; i)"z`POST { "email": "...", "password": "..." } -> { "success": true, "token": "...", "user": {...} }emailusername passwordsuccessFerrorz Email and password are required.i  )statusN)r    r"   )email__iexactzInvalid credentials.i  is_staffis_superuserzAdmin access required.i  useradminTtokenr*   idnamer   business_id:N   N)r    )update_fieldsuser_id)r   r'   r(   )datagetstripr   r   r   r   objectsfilterfirst	Exceptiongetattrr   get_or_createkeystrr   r   r   set_unusable_passwordr   r'   r(   saver-   )request
identifierr"   legacy
DjangoUserdjango_userauthed	candidateauthed2r,   _r   stored_hashdjango_usernamecreateds   &              r   master_loginrL      s   
 	!GGW\\%5%5j%AGGReg    ,2299;HXE74VW`cdd
+F6 $%
 gXN K!&..55J5OUUW	 $&wJXZ9[fno&")KYw8NOX[\\Z777;P^`e;f;fYw8PQZ]^^==..K.@!+~uEEw7tUYYc'+tR89GKR@FFBGW['2>DD"Et

 
 
	 ::j)//R668K4XKKE74JKTWXX!&**V"45D4  E74LMVYZZ!J&**Z0UUFJJw4GUU:VW[\O%--;;_;UK))+FJJw/5526KK#K#H\cZLik#lm}}***<HE4#fjj+=={~~>C

6*JJfjj.DJJKSG,223D6::m4

 
 
_  ! 	!s    *Q6 6RRGETc                    \        RR/4      # )u2   GET — returns success if the DRF token is valid.r#   Tr   r@   s   &r   master_validate_tokenrP   j   s     Y%&&r   c                     V P                   P                  P                  4        \	        RR/4      #   \         d     Li ; i)u5   POST — deletes the DRF token (invalidates session).r#   T)r*   
auth_tokendeleter9   r   rO   s   &r   master_logoutrT   q   sC    &&( Y%&&  s   $3 A Ac                    \         P                  P                  V P                  R7      w  r\	        RRRVP
                  /4      # )u<   POST — DRF tokens don't expire; return the existing token.r)   r#   Tr,   )r   r6   r;   r*   r   r<   )r@   r,   rH   s   &  r   master_refreshrV   |   s9     }}***=HEYguyy9::r   c                   V P                   p\        VRR4      ;'       g    \        VRR4      ;'       g    RP                  4       pV'       d   \        V4      MRp\	        RRRR\        V'       d   VP                  R	4      M\        VRR4      4      R
\        T;'       g    / P                  R
4      ;'       g1    T;'       g    / P                  R4      ;'       g    \        VRR4      4      R\        T;'       g    / P                  R4      ;'       g    \        VRR4      4      R\        T;'       g    / P                  R4      ;'       g    VP                  '       d   RMR4      RT;'       g    / P                  R4      //4      # )u(   GET — return current master user info.r   Nr    r!   r#   Tr*   r-   r2   r.   r   r+   agentr/   )	r*   r:   r5   r   r   r=   r4   r   r'   )r@   uidentrB   s   &   r   	master_mer[      sI    	AQ&LL'!Z*FLL"SSUE*/&TF4#vfjj+71dB;OPC2**62rrv||6H6H6TrrX_`acmoqXrsS&,,B++G4OO7B8OP*FLLb+=+=f+E+m+mUVU_U_U_'elnFLLb--m<
	 	 	r   N>   r+   owner
superadminsuper_admin)
__future__r   django.contrib.authr   r   rest_framework.authtoken.modelsr   rest_framework.decoratorsr   r   rest_framework.permissionsr	   r
   rest_framework.responser   config.auth_viewsr   r   r   	frozensetr   r   rL   rP   rT   rV   r[   r   r   r   <module>rg      s	   " . , 1 B @ , ` `IJ9 
6(XJR   Rj 
5'_%&' ' '
 
6(_%&' ' ' 
6(_%&; ' ; 
5'_%& ' r   