
    	]j                     :   d Z ddlZ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 ddlmZ d	Zd
ZdZde dZde dZdZdZddddddeffZ ej.                  e      Z G d dej4                        Z G d dej4                        Z G d dej:                        Zy)zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    N)forms)settings)auth)validate_password)ValidationError)User      d   zPlease enter a username z characters or fewer in lengthzPlease enter a display name z/The email and password you entered don't match.Other)GiGithub)EmzEmail or newsletter)SezSearch engine)FrzFriend or coworker)Adr   Otc                       e Zd ZdZej
                  r ej                  d      n ej                  d      Z	 ej                   ej                               Z ej                   ej                         d      Z fdZ xZS )		LoginFormz1For logging in to the app and all - session basedr   )labelEmailwidgetF)r   requiredc                    t         t        |          }|j                  dd      j	                         }|j                  dd      }t        |      t        k\  rt        j                  d      t        j                  t        ||      }|t        j                  ||      }|r#|j                  r|j                  dd      }||dS t        j                  t              )	Nemail passwordEmail is too long)r   r   persist_sessionF)userr    )superr   cleangetlowerlenEMAIL_MAX_LENGTHr   r   r   	USER_AUTHr   r   authenticate	is_activeINVALID_USER_ERROR)	selfargskwargscleanedr   r   r!   r    	__class__s	           B/root/env/lib/python3.12/site-packages/label_studio/users/forms.pyr#   zLoginForm.clean(   s    	4.0GR(..0;;z2.u:))''(;<< !!$x8 <$$58DDDNN%kk*;UCO _EE''(:;;    )__name__
__module____qualname____doc__r   USE_USERNAME_FOR_LOGINr   	CharField
EmailFieldr   PasswordInputr   BooleanFieldCheckboxInputr    r#   __classcell__)r0   s   @r1   r   r       sy    ; .6-L-LOEOO&)RbRWRbRbipRqEu&9e&9&9&;<H(e((0C0C0C0EPUVO< <r2   r   c                      e Zd Z ej                  dddi      Z ej                   ej                  ddi            Z ej                  d	
      Z
 ej                  d	
      Z ej                  d	
      Zd Zd Zd Zd Zy)UserSignupFormz
Work Emailr   zInvalid email)r   error_messagestyper   )attrsr   F)r   c                     | j                   j                  d      }	 t        |       |S # t        $ r$}t	        j
                  |j                        d }~ww xY w)Nr   )cleaned_datar$   r   DjangoValidationErrorr   r   messages)r,   r   es      r1   clean_passwordzUserSignupForm.clean_passwordD   sS    $$((4	4h'  % 	4''

33	4s   * 	AAAc                     | j                   j                  d      }|rQt        j                  j	                  |j                               j                         rt        j                  d      |S )Nusername)rJ   z!User with username already exists)	rD   r$   r   objectsfilterr%   existsr   r   )r,   rJ   s     r1   clean_usernamezUserSignupForm.clean_usernameL   sV    $$((4++X^^5E+FMMO''(KLLr2   c                 0   | j                   j                  d      j                         }t        |      t        k\  rt        j                  d      |rCt        j                  j                  |      j                         rt        j                  d      |S )Nr   r   )r   z#User with this email already exists)rD   r$   r%   r&   r'   r   r   r   rK   rL   rM   )r,   r   s     r1   clean_emailzUserSignupForm.clean_emailR   sw    !!%%g.446u:))''(;<<T\\((u(5<<>''(MNNr2   c                     | j                   }|d   }|d   j                         }d }d }d|v r|d   }d|v r|d   }d|v r|t        k(  r|d    t        j                  j                  |||      }|S )Nr   r   allow_newslettershow_find_us	elaborate)rR   )rD   r%   FOUND_US_ELABORATEr   rK   create_user)r,   r/   r   r   rR   rS   r!   s          r1   savezUserSignupForm.save\   s    ##:& &&( ') '(; <G#!-0K'!k5G&GK ||''xK\']r2   N)r3   r4   r5   r   r9   r   r8   	TextInputr   r;   rR   rS   rT   rH   rN   rP   rW    r2   r1   r?   r?   =   s    E<_@]^EuoeooVZ<P&QRH***E:!%//51K/Ir2   r?   c                   $    e Zd ZdZ G d d      Zy)UserProfileFormz*This form is used in profile account pagesc                       e Zd ZeZdZy)UserProfileForm.Meta)
first_name	last_namephonerR   N)r3   r4   r5   r   modelfieldsrY   r2   r1   Metar]   p   s    Jr2   rc   N)r3   r4   r5   r6   rc   rY   r2   r1   r[   r[   m   s    4K Kr2   r[   )r6   loggingdjangor   django.confr   django.contribr   'django.contrib.auth.password_validationr   django.core.exceptionsr   rE   users.modelsr   r'   USERNAME_MAX_LENGTHDISPLAY_NAME_LENGTHUSERNAME_LENGTH_ERRDISPLAY_NAME_LENGTH_ERRr+   rU   FOUND_US_OPTIONS	getLoggerr3   loggerFormr   r?   	ModelFormr[   rY   r2   r1   <module>rt      s         E K    01D0EEcd 89L8MMkl F  ! 	  
		8	$<

 <:-UZZ -`Keoo Kr2   