
    Bh                         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
y
)    )forms)get_user_model)ReadOnlyPasswordHashField   )	EmailUserc                        e Zd ZdZdddZ ej                  dd      Z ej                  dej                  	      Z
 ej                  d
ej                  d      Z G d d      Zd Zd Zd fd	Z xZS )UserCreationFormz_
    A form for creating a new user, including the required
    email and password fields.
    z&A user with that email already exists.z%The two password fields didn't match.)duplicate_emailpassword_mismatchEmail)Required.  Standard format email address.label	help_textPassword)r   widgetzPassword confirmationz3Enter the same password as above, for verification.)r   r   r   c                       e Zd ZeZdZy)UserCreationForm.MetaemailN__name__
__module____qualname__r   modelfields     Y/home/dcms/DCMS/lib/python3.12/site-packages/cms/test_utils/project/emailuserapp/forms.pyMetar   #   s    r   r    c                     | j                   d   }t               }	 |j                  j                  |       t        j                  | j                  d   d      # |j                  $ r |cY S w xY w)Nr   r   r
   code)cleaned_datar   _default_managergetDoesNotExistr   ValidationErrorerror_messages)selfr   Users      r   clean_emailzUserCreationForm.clean_email'   s{     !!'*	!!%%E%2 ## 12"
 	
    	L	s   A A/.A/c                     | j                   j                  d      }| j                   j                  d      }|r+|r)||k7  r$t        j                  | j                  d   d      |S )N	password1	password2r   r"   )r$   r&   r   r(   r)   )r*   r.   r/   s      r   clean_password2z UserCreationForm.clean_password27   sg    %%))+6	%%))+6	yI'=''##$78(  r   c                     t         |   d      }|j                  | j                  d          |r|j                          |S )NF)commitr.   )supersaveset_passwordr$   )r*   r2   user	__class__s      r   r4   zUserCreationForm.saveB   s=    w|5|)$++K89IIKr   )T)r   r   r   __doc__r)   r   
EmailFieldr   	CharFieldPasswordInputr.   r/   r    r,   r0   r4   __classcell__r7   s   @r   r	   r	      s     DDN
 E=E
  ""I
  %""GI 
 	 r   r	   c                   x     e Zd ZdZ ej
                  dd      Z edd      Z G d d      Z	 fd	Z
d
 Z xZS )UserChangeFormz
    A form for updating users, including all fields on the user,
    but replaces the password field with admin's password hash display
    field.
    r   r   r   r   zRaw passwords are not stored, so there is no way to see this user's password, but you can change the password using <a href="password/">this form</a>.c                       e Zd ZeZdZy)UserChangeForm.Meta)r   password
first_name	last_name	is_activeis_staffis_superusergroupsuser_permissions
last_logindate_joinedNr   r   r   r   r    rA   ]   s    
r   r    c                     t        |   |i | | j                  j                  dd       }|!|j                  j                  d      |_        y y )NrI   content_type)r3   __init__r   r&   querysetselect_related)r*   argskwargsfr7   s       r   rN   zUserChangeForm.__init__e   sJ    $)&)KKOO.5=22>BAJ r   c                      | j                   d   S )z
        Regardless of what the user provides, return the initial value.
        This is done here, rather than on the field, because the
        field does not have access to the initial value.
        rB   )initial)r*   s    r   clean_passwordzUserChangeForm.clean_passwordk   s     ||J''r   )r   r   r   r8   r   r9   r   r   rB   r    rN   rV   r<   r=   s   @r   r?   r?   L   sL    
 E=E
 )_H
 
C(r   r?   N)djangor   django.contrib.authr   django.contrib.auth.formsr   modelsr   	ModelFormr	   r?   r   r   r   <module>r\      s4     . ? Au AH%(U__ %(r   