U
    VÉcî
  ã                   @   s\   d dl Z d dlmZ d dlmZ dd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )é    N)Úserializers)Úutilsc                 C   s   t  d| ¡st d¡‚| S )zE
    This function checks if the incoming email is valid or not!
    u]   ^[\w!#$%&â€™*+/=?`{|}~^-]+(?:\.[\w!#$%&â€™*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$zEnter a valid email address©ÚreÚmatchr   ÚValidationError)Úemail© r	   ú3/var/www/wikiazma_server/authenticate/validators.pyÚemail_validator   s    
r   c                 C   sR   |   ¡ st d¡‚t | ¡} |  ¡ s.t d¡‚t | ¡} t| ƒdkrNt d¡‚| S )zE
    This function checks if the incoming phone is valid or not!
    z!phone characters should be digitszEnter a valid phoneé   )Úisdigitr   r   r   Z0replace_phone_persian_digits_with_english_digitsÚisasciiZiran_phone_number_modifierÚlen)Úphoner	   r	   r
   Úphone_validator   s    




r   c                 C   s>   dt | ƒ  k rdk s$n t d¡‚t d| ¡s:t d¡‚| S )zv
    This function checks if the incoming password is strong or not!
    it should be between 8 to 50 characters.
    é   é   z4Password length should be between 8 to 20 charactersz^(?=.*[A-Z])(?=.*\d)z@Password should contain at least an uppercase letter and a digit)r   r   r   r   r   )Úpasswordr	   r	   r
   Úpassword_validator#   s    ÿÿr   c                 C   s   t  d| ¡st d¡‚| S )zt
    This function checks if the incoming code is valid or not!
    it should has exactly 8 integer characters.
    z
^[0-9]{6}$zEnter a valid verification coder   )Úcoder	   r	   r
   Úcode_validator1   s    
r   c                 C   sH   t | ƒtk	s d| ks t| ƒdkr*t d¡‚t| d ƒdkrDt d¡‚| S )zM
    This function gets info as its argument and checks the format of it
    Zbioé   zInfo format is incorrecti¸  z)bio can not has more than 3000 characters)ÚtypeÚdictr   r   r   )Úinfor	   r	   r
   Úinfo_validator;   s     
ÿr   c                 C   s6   |   dd ¡}|   dd ¡}|s |r(|r2|r2t d¡‚d S )Nr   r   zYou should send phone or email©Úgetr   r   )Údatar   r   r	   r	   r
   Ú&make_email_or_phone_required_validatorG   s    r    c                 C   sR   |   dd ¡}|   dd ¡}|   dd ¡}|d k	|d k	 |d k	 }|dkrNt d¡‚d S )Nr   r   Úusernamer   z*You should send phone or email or usernamer   )r   r   r   r!   Úcountr	   r	   r
   Ú2make_email_or_phone_or_username_required_validatorN   s    r#   )r   Úrest_frameworkr   Úauthenticater   r   r   r   r   r   r    r#   r	   r	   r	   r
   Ú<module>   s   	
