o
    gf                     @   s`   d dl mZ d dlmZ d dlmZ d dlmZmZ dd Z	dd Z
d	d
 Zdd Zdd ZdS )    )REDIRECT_FIELD_NAME)UserSocialAuth)get_backends)group_backend_by_typeLazyDictc                        fdd}dt |iS )z~Load Social Auth current user data to context.
    Will add a output from backends_data to context under social_auth key.
    c                      s
   t  jS N)backends_datauser requestr   _/var/www/html/humari/django-venv/lib/python3.10/site-packages/social_auth/context_processors.pycontext_value   s   
z+social_auth_backends.<locals>.context_valuesocial_authr   r   r   r   r   r   social_auth_backends   s   r   c                    r   )zLoad Social Auth current user data to context.
    Will add a output from backends_data to context under social_auth key where
    each entry will be grouped by backend type (openid, oauth, oauth2).
    c                     sF   t  j} t| d | d< t| d | d< t| d dd d| d< | S )Nbackendsnot_associated
associatedc                 S   s   | j S r   provider)assocr   r   r   <lambda>   s    zEsocial_auth_by_type_backends.<locals>.context_value.<locals>.<lambda>)key)r	   r
   r   )datar   r   r   r      s   

z3social_auth_by_type_backends.<locals>.context_valuer   r   r   r   r   r   social_auth_by_type_backends   s   	r   c                    r   )a  Load Social Auth current user data to context.
    Will add a social_auth object whose attribute names are the names of each
    provider, e.g. social_auth.facebook would be the facebook association or
    None, depending on the logged in user's current associations. Providers
    with a hyphen have the hyphen replaced with an underscore, e.g.
    google-oauth2 becomes google_oauth2 when referenced in templates.
    c                     sb   dd t   D } tt| d gt|  } j}t|dr/| r/|dd t	
|D  |S )Nc                 S   s   g | ]}|qS r   r   ).0r   r   r   r   
<listcomp>.   s    zGsocial_auth_by_name_backends.<locals>.context_value.<locals>.<listcomp>is_authenticatedc                 s   s    | ]}|j |fV  qd S r   r   r   r   r   r   r   	<genexpr>2   s    zFsocial_auth_by_name_backends.<locals>.context_value.<locals>.<genexpr>)r   keysdictziplenr
   hasattrr    updater   get_social_auth_for_user)r#   accountsr
   r   r   r   r   -   s   
z3social_auth_by_name_backends.<locals>.context_valuer   r   r   r   r   r   social_auth_by_name_backends%   s   r+   c                 C   sd   t   }g ||d}t| dr0|  r0t| }tt|tdd |D  }||d< ||d< |S )a  Return backends data for given user.

    Will return a dict with values:
        associated: UserSocialAuth model instances for currently
                    associated accounts
        not_associated: Not associated (yet) backend names.
        backends: All backend names.

    If user is not authenticated, then first list is empty, and there's no
    difference between the second and third lists.
    )r   r   r   r    c                 s   s    | ]}|j V  qd S r   r   r!   r   r   r   r"   N   s    z backends_data.<locals>.<genexpr>r   r   )r   r#   r'   r    r   r)   listset)r
   	availablevaluesr   r   r   r   r   r	   8   s   

r	   c                 C   s.   | j t}|rtd | }nd}t||dS )z!Load current redirect to context.= )r   REDIRECT_FIELD_VALUEredirect_querystring)REQUESTgetr   )r   redirect_valuer3   r   r   r   social_auth_login_redirectT   s   r7   N)django.contrib.authr   social_auth.modelsr   social_auth.backendsr   social_auth.utilsr   r   r   r   r+   r	   r7   r   r   r   r   <module>   s    	