
    s7h                        d dl mZ d dlmZ d dlmZ d dlmZ  G d dej                        Z	 G d dej                        Zd dlmZ d	d
lmZmZ d dlmZ  G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Zy)    )VALIDATION_ERR)forms)	UserModel)ValidationErrorc                   p    e Zd Z ej                  dd      Z ej                  ej                  d      Zy)formConnexion2   zNom d'utilisateur)
max_lengthlabelMot de passewidgetr   N)__name__
__module____qualname__r   	CharFieldusernamePasswordInputpassword     '/var/www/html/djangosite/dsite/forms.pyr   r      s-    u"4GHHue&9&9PHr   r   c                   |     e Zd Z ej                  ej
                  d      Z G d d      Zd Zd Z	d fd	Z
 xZS )	
formSignupr   r   c                       e Zd ZeZddgZy)formSignup.Metar   emailN)r   r   r   r   modelfieldsr   r   r   Metar      s    g&r   r    c                    | j                   j                  d      }t        |      dk  rt        d      t	        d |D              st        d      t	        d |D              st        d      t	        d |D              st        d	      d
dl}t        |j                        t	        fd|D              st        d      |S )  
        Vérifie que le mot de passe respecte les critères de complexité:
        - Au moins 8 caractères
        - Au moins un chiffre
        - Au moins une lettre majuscule
        - Au moins une lettre minuscule
        - Au moins un symbole (caractère spécial)
        r      5   Le mot de passe doit contenir au moins 8 caractères.c              3   <   K   | ]  }|j                           y wNisdigit.0chars     r   	<genexpr>z,formSignup.clean_password.<locals>.<genexpr>#        7d4<<>7   2Le mot de passe doit contenir au moins un chiffre.c              3   <   K   | ]  }|j                           y wr&   isupperr)   s     r   r,   z,formSignup.clean_password.<locals>.<genexpr>'   r-   r.   <Le mot de passe doit contenir au moins une lettre majuscule.c              3   <   K   | ]  }|j                           y wr&   islowerr)   s     r   r,   z,formSignup.clean_password.<locals>.<genexpr>+   r-   r.   <Le mot de passe doit contenir au moins une lettre minuscule.r   Nc              3   &   K   | ]  }|v  
 y wr&   r   r*   r+   special_charss     r   r,   z,formSignup.clean_password.<locals>.<genexpr>1        >T4=(>   N   Le mot de passe doit contenir au moins un caractère spécial (!, @, #, etc.).cleaned_datagetlenr   anystringsetpunctuationselfr   rC   r:   s      @r   clean_passwordzformSignup.clean_password   s     $$((4 x=1!"YZZ 7h77!"VWW 7h77!"`aa 7h77!"`aa 	F../>X>>!"rssr   c                 <    | j                   j                  d      }|S )Nr   )r?   r@   )rG   r   s     r   cleanPwdConfirmzformSignup.cleanPwdConfirm6   s    $$((4r   c                     t         |   d      }|j                  | j                  d          |r|j                          |S )NF)commitr   )supersaveset_passwordr?   )rG   rL   user	__class__s      r   rN   zformSignup.save:   s=    w|5|)$++J78IIKr   )T)r   r   r   r   r   r   r   r    rH   rJ   rN   __classcell__rQ   s   @r   r   r      s:    ue&9&9PH' '!F r   r      )ProtectedFileUserFile)Userc                       e Zd Z ej                  ej                  j                         dej                        Z	 G d d      Z
y)ProtectedFileFormF)querysetrequiredr   c                       e Zd ZeZg dZy)ProtectedFileForm.Meta)titlefileallowed_usersN)r   r   r   rU   r   r   r   r   r   r    r]   M   s    3r   r    N)r   r   r   r   ModelMultipleChoiceFieldrW   objectsallCheckboxSelectMultipler`   r    r   r   r   rY   rY   F   s:    2E22!!#++M4 4r   rY   c                   f    e Zd ZdZ ej
                  dd ej                  ddi            Zd Zy	)
FileUploadFormz5
    Formulaire simple pour l'upload de fichiers
    u   Sélectionner un fichierzTaille max: 50MBclasszupload-inputattrs)r   	help_textr   c                 t    | j                   j                  d      }|r|j                  dkD  rt        d      |S )Nr_   i   z5Le fichier est trop volumineux. Taille maximum: 50MB.)r?   r@   sizer   )rG   r_   s     r   
clean_filezFileUploadForm.clean_file[   s9      $$V,yy++%&]^^r   N)	r   r   r   __doc__r   	FileFieldClearableFileInputr_   rm   r   r   r   rf   rf   Q   s9     5??($'u''w.GHDr   rf   c            
       
   e Zd ZdZddgZ ej                  ej                  j                         j                  d      ddd ej                  dd	i
            Z ej                  ed ej                  ddi
            Zy)FileEditFormuR   
    Formulaire pour modifier le propriétaire et la visibilité d'un fichier
    )privateu   Privé)publicPublicr   Fu   Propriétaireu   Public (aucun propriétaire)rg   zform-controlrh   )rZ   r[   r   empty_labelr   u   Visibilitézvisibility-radio)choicesr   r   N)r   r   r   rn   VISIBILITY_CHOICESr   ModelChoiceFieldrW   rb   rc   order_bySelectrP   ChoiceFieldRadioSelect
visibilityr   r   r   rr   rr   b   s     	
 "5!!!!#,,Z82u||7N";<D #""" u  1C'DEJr   rr   c                   f    e Zd ZdZ ej
                  dd ej                  ddi            Zd Zy	)
PasswordResetFormuH   
    Formulaire pour demander une réinitialisation de mot de passe
    Email   placeholderzAdresse e-mailrh   )r   r
   r   c                     | j                   j                  d      }t        j                  j	                  |      j                         st        d      |S )Nr   )r   u4   Aucun compte n'est associé à cette adresse e-mail.)r?   r@   rW   rb   filterexistsr   )rG   r   s     r   clean_emailzPasswordResetForm.clean_email   sG    !!%%g.||"""/668!"XYYr   N)	r   r   r   rn   r   
EmailField
EmailInputr   r   r   r   r   r   r   y   s<     Eu}6F&GHEr   r   c                       e Zd ZdZ ej
                  d ej                  ddi            Z ej
                  d ej                  ddi            Zd Z	d	 Z
y
)SetPasswordFormu:   
    Formulaire pour définir un nouveau mot de passe
    zNouveau mot de passer   rh   )r   r   zConfirmation du mot de passezConfirmez le mot de passec                    | j                   j                  d      }t        |      dk  rt        d      t	        d |D              st        d      t	        d |D              st        d      t	        d |D              st        d	      d
dl}t        |j                        t	        fd|D              st        d      |S )r"   new_password1r#   r$   c              3   <   K   | ]  }|j                           y wr&   r'   r)   s     r   r,   z6SetPasswordForm.clean_new_password1.<locals>.<genexpr>   r-   r.   r/   c              3   <   K   | ]  }|j                           y wr&   r1   r)   s     r   r,   z6SetPasswordForm.clean_new_password1.<locals>.<genexpr>   r-   r.   r3   c              3   <   K   | ]  }|j                           y wr&   r5   r)   s     r   r,   z6SetPasswordForm.clean_new_password1.<locals>.<genexpr>   r-   r.   r7   r   Nc              3   &   K   | ]  }|v  
 y wr&   r   r9   s     r   r,   z6SetPasswordForm.clean_new_password1.<locals>.<genexpr>   r;   r<   r=   r>   rF   s      @r   clean_new_password1z#SetPasswordForm.clean_new_password1   s     $$((9 x=1!"YZZ 7h77!"VWW 7h77!"`aa 7h77!"`aa 	F../>X>>!"rssr   c                     | j                   j                  d      }| j                   j                  d      }|r|r||k7  rt        d      |S )Nr   new_password2z'Les mots de passe ne correspondent pas.)r?   r@   r   )rG   	password1	password2s      r   clean_new_password2z#SetPasswordForm.clean_new_password2   sL    %%))/:	%%))/:	yI'=!"KLLr   N)r   r   r   rn   r   r   r   r   r   r   r   r   r   r   r   r      sh     $EOO$"u""-9O)PQM $EOO,"u""-9T)UVM
!Fr   r   c                   v     e Zd ZdZ ej
                  ddd      Z ej
                  ddd      Z fdZ xZ	S )	UserEditFormz>
    Formulaire pour modifier les droits d'un utilisateur
    FAdministrateuru?   Cochez pour donner les droits administrateur à cet utilisateur)r[   r   rj   zCompte actifu6   Décochez pour désactiver le compte sans le supprimerc                     |j                  dd       }t        t        |   |i | |r=|j                  | j
                  d   _        |j                  | j
                  d   _        y y )NrP   is_staff	is_active)poprM   r   __init__r   r   initialr   )rG   argskwargsrP   rQ   s       r   r   zUserEditForm.__init__   sY    zz&$'lD*D;F;.2mmDKK
#+/3~~DKK$, r   )
r   r   r   rn   r   BooleanFieldr   r   r   rR   rS   s   @r   r   r      sL     "u!!SH #""JI> >r   r   c                   b    e Zd ZdZ ej
                   ej                  ddd      dd      Zy	)
NoteFormz1
    Formulaire pour les notes d'utilisateur
    noteContentu   Écrivez votre note ici...)idr   rh   F )r   r[   r   N)r   r   r   rn   r   r   Textareacontentr   r   r   r   r      s3     eoou~~=Ie$fgGr   r   N)xml.domr   djangor   6django.contrib.auth.management.commands.changepasswordr   django.core.exceptionsr   Formr   	ModelFormr   modelsrU   rV   django.contrib.auth.modelsrW   rY   rf   rr   r   r   r   r   r   r   r   <module>r      s    "  L 2QEJJ Q3 3l  + +	4 	4UZZ "5:: .

 "5ejj 5n>5:: >0uzz r   