o
    h                     @   s   d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZmZ G dd dejZG dd	 d	eZG d
d deZG dd dejZG dd deZG dd deZG dd dejZG dd dejZdS )    )forms)UserGroup
Permission)UserCreationFormUserChangeForm)authenticate)Tenant
TenantUserc                       sv   e Zd ZejdejdddddddZejd	ejdd
ddddZejejddddddZ	 fddZ
  ZS )TenantLoginForm   form-controlzEnter organization codeT)classplaceholderrequiredattrszOrganization Code)
max_lengthwidgetlabel   zEnter username)r   r   zEnter password)r   c           	         s*  t   }|d}|d}|d}|r|r|rztjj|ddgd}W n tjy3   tdw t||d}|sAtd	|j	sItd
z<t
jj||dd}d|jv rw|jddd }tjj|d rw| | krwtd||d< ||d< ||d< W |S  t
jy   tdw |S )Ntenant_codeusernamepasswordactivetrial)r   
status__inzInvalid organization code.)r   r   zInvalid username or password.z:Your account has been deactivated. Please contact support.T)usertenant	is_active_   r   )tenant_code__iexactz#Access denied to this organization.r   r   tenant_userz,You do not have access to this organization.)supercleangetr	   objectsDoesNotExistr   ValidationErrorr   r   r
   r   splitfilterexistslower)	selfcleaned_datar   r   r   r   r   r#   prefix	__class__ "/var/www/html/pos/authapp/forms.pyr%   "   s<   










zTenantLoginForm.clean)__name__
__module____qualname__r   	CharField	TextInputr   r   PasswordInputr   r%   __classcell__r3   r3   r1   r4   r      s4    	r   c                   @   s>   e Zd ZejddZejej	 dej
dZG dd dZdS )UserFormTr   Fquerysetr   r   c                   @      e Zd ZeZg dZdS )zUserForm.Meta)r   email	password1	password2groupsNr5   r6   r7   r   modelfieldsr3   r3   r3   r4   MetaT       rH   N)r5   r6   r7   r   
EmailFieldrA   ModelMultipleChoiceFieldr   r'   allCheckboxSelectMultiplerD   rH   r3   r3   r3   r4   r<   P   s    r<   c                   @   sB   e Zd ZdZejddZejej	
 dejdZG dd dZdS )EditUserFormNTr=   Fr>   c                   @   r@   )zEditUserForm.Meta)r   rA   rD   NrE   r3   r3   r3   r4   rH   ^   rI   rH   )r5   r6   r7   r   r   rJ   rA   rK   r   r'   rL   rM   rD   rH   r3   r3   r3   r4   rN   Y   s
    rN   c                   @      e Zd ZG dd dZdS )	GroupFormc                   @      e Zd ZeZdgZdS )zGroupForm.MetanameNr5   r6   r7   r   rF   rG   r3   r3   r3   r4   rH   d       
rH   Nr5   r6   r7   rH   r3   r3   r3   r4   rP   c       rP   c                   @   rO   )CustomUserCreationFormc                   @   r@   )zCustomUserCreationForm.Meta)r   rA   
first_name	last_namerB   rC   rD   NrE   r3   r3   r3   r4   rH   j   rI   rH   NrU   r3   r3   r3   r4   rW   i   rV   rW   c                   @   rO   )CustomUserChangeFormc                   @   r@   )zCustomUserChangeForm.Meta)r   rA   rX   rY   rD   NrE   r3   r3   r3   r4   rH   p   rI   rH   NrU   r3   r3   r3   r4   rZ   o   rV   rZ   c                   @   s2   e Zd Zejej ejddZ	G dd dZ
dS )GroupPermissionFormF)r?   r   r   c                   @   rQ   )zGroupPermissionForm.MetapermissionsNrS   r3   r3   r3   r4   rH   |   rT   rH   N)r5   r6   r7   r   rK   r   r'   rL   rM   r\   rH   r3   r3   r3   r4   r[   u   s    r[   c                       s   e Zd ZejdejdddddddZejd	ejdd
dddddZ	ejdejddddddZ
G dd dZdd Zd fdd	Z  ZS )EditProfileFormzProfile Picturer   zimage/*)r   acceptr   Fz2Upload a profile picture (JPG, PNG, GIF - Max 2MB))r   r   r   	help_textzNew PasswordzEnter new passwordr   r   z5Leave blank if you don't want to change your passwordzConfirm New PasswordzConfirm new password)r   r   r   c                   @   sN   e Zd ZeZg dZejddddejddddejdddddZ	dS )	zEditProfileForm.Meta)rX   rY   rA   r   zEnter first namer`   r   zEnter last namezEnter email addressN)
r5   r6   r7   r   rF   rG   r   r9   
EmailInputwidgetsr3   r3   r3   r4   rH      s    
rH   c                 C   s^   | j d}| j d}|r|r||krtd|S |r$|s$td|r-|s-td|S )Nnew_password1new_password2zPasswords don't matchz Please confirm your new passwordzPlease enter your new password)r/   r&   r   r)   )r.   rB   rC   r3   r3   r4   clean_new_password2   s   


z#EditProfileForm.clean_new_password2Tc                    s8   t  jdd}| jd}|r|| |r|  |S )NF)commitrc   )r$   saver/   r&   set_password)r.   rf   r   new_passwordr1   r3   r4   rg      s   
zEditProfileForm.save)T)r5   r6   r7   r   
ImageField	FileInputprofile_picturer8   r:   rc   rd   rH   re   rg   r;   r3   r3   r1   r4   r]      s*    	r]   N)djangor   django.contrib.auth.modelsr   r   r   django.contrib.auth.formsr   r   django.contrib.authr   tenants.modelsr	   r
   Formr   r<   rN   	ModelFormrP   rW   rZ   r[   r]   r3   r3   r3   r4   <module>   s    H	
