U
    M+|jz  ã                   @   s<   d dl mZ d dlmZ e ¡ Zdd„ Zdd„ Zdd„ Zd	S )
é    )Údb)Úauthc                 C   sN   zt j | ¡}W n t jk
r*   d}Y nX |js6d}|dkrJt ƒ  d¡ |S )zÒ
    Return the UserModel instance for `username`.

    If no matching user exists, or if the user is inactive, return None, in
    which case the default password hasher is run to mitigate timing attacks.
    NÚ )Ú	UserModelÚ_default_managerÚget_by_natural_keyÚDoesNotExistÚ	is_activeÚset_password)ÚusernameÚuser© r   úlc:\users\snmko\desktop\web_content\django_cbt\venv\Lib\site-packages\django/contrib/auth/handlers/modwsgi.pyÚ	_get_user   s    
r   c                 C   s6   t  ¡  zt|ƒ}|r$| |¡W ¢S W 5 t  ¡  X dS )a9  
    Authenticate against Django's auth database.

    mod_wsgi docs specify None, True, False as return value depending
    on whether the user exists and authenticates.

    Return None if the user does not exist, return False if the user exists but
    password is not correct, and return True otherwise.

    N)r   Úreset_queriesÚclose_old_connectionsr   Úcheck_password)Úenvironr   Úpasswordr   r   r   r   r      s    r   c                 C   sn   t  ¡  zVztj |¡}W n tjk
r8   g  Y W ¢*S X |jsHg W ¢S dd„ |j 	¡ D ƒW ¢S t  ¡  X dS )z*
    Authorize a user based on groups
    c                 S   s   g | ]}|j  ¡ ‘qS r   )ÚnameÚencode)Ú.0Úgroupr   r   r   Ú
<listcomp>@   s     z#groups_for_user.<locals>.<listcomp>N)
r   r   r   r   r   r   r   r	   ÚgroupsÚall)r   r   r   r   r   r   Úgroups_for_user4   s    r   N)	Zdjangor   Zdjango.contribr   Zget_user_modelr   r   r   r   r   r   r   r   Ú<module>   s
   