
    )JfX                     ~    d dl mZ d dlmZ d dlmZ  G d de          Z G d de          Z	 G d d	e          Z
d
S )    )ImproperlyConfigured)app_settingsget_adapterc                       e Zd ZdS )ProviderExceptionN)__name__
__module____qualname__     p/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/allauth/socialaccount/providers/base/provider.pyr   r      s        Dr   r   c                       e Zd ZdZdZddZed             ZddZd Z	d Z
d Zd	 Zd
 Zd Zd ZddZd Zed             ZdS )ProviderNTc                 R    || _         | j        r|t          d          || _        d S )Nzmissing: app)request	uses_apps
ValueErrorapp)selfr   r   s      r   __init__zProvider.__init__   s0    > 	-ck^,,,r   c                     | j         p| j        S N)slugid)clss    r   get_slugzProvider.get_slug   s    x!36!r   c                 0    t          d| j        z             )zb
        Builds the URL to redirect to when initiating a login for this
        provider.
        zget_login_url() for )NotImplementedErrorname)r   r   nextkwargss       r   get_login_urlzProvider.get_login_url   s    
 ""849"DEEEr   c                     dS )zT
        Some providers may require extra scripts (e.g. a Facebook connect)
         r   )r   r   s     r   media_jszProvider.media_js    s	     rr   c                 ,    |                      |          S r   )account_classr   social_accounts     r   wrap_accountzProvider.wrap_account&   s    !!.111r   c                 L    t           j                            | j        i           S r   )r   	PROVIDERSgetr   r   s    r   get_settingszProvider.get_settings)   s    %))$'2666r   c                 l   ddl m} ddlm}m}  |            }|                     |          }t          |t                    st          dt          |                     t          |          t          j        k    r t          dt          |           d          |st          d          |                     |          }|                     |          }	 |||| j        r| j        j        p| j        j        n| j                  }
|                     |          }|                     |	                    d	          ||	                    d
                      ||
|          }|                    ||          x}|_        |                                 |                    |||	           |S )a|  
        Instantiates and populates a `SocialLogin` model based on the data
        retrieved in `response`. The method does NOT save the model to the
        DB.

        Data for `SocialLogin` will be extracted from `response` with the
        help of the `.extract_uid()`, `.extract_extra_data()`,
        `.extract_common_fields()`, and `.extract_email_addresses()`
        methods.

        :param request: a Django `HttpRequest` object.
        :param response: object retrieved via the callback response of the
            social auth provider.
        :return: A populated instance of the `SocialLogin` model (unsaved).
        r   r   )SocialAccountSocialLoginzuid must be a string: z)SOCIALACCOUNT_UID_MAX_LENGTH too small (<)zuid must be a non-empty string)
extra_datauidprovideremailemail_verified)r9   )accountemail_addresses)allauth.socialaccount.adapterr   allauth.socialaccount.modelsr2   r3   extract_uid
isinstancestrr   reprlenr   UID_MAX_LENGTHr   extract_extra_dataextract_common_fieldsr   provider_idr7   r   extract_email_addressescleanup_email_addressesr.   new_useruserset_unusable_passwordpopulate_user)r   r   responser   r2   r3   adapterr6   r5   common_fieldssocialaccountr;   socialloginrJ   s                 r   sociallogin_from_responsez"Provider.sociallogin_from_response,   s   " 	>=====KKKKKKKK+--x((#s## 	CAd3iiAABBBs88l111&GCHHGGG    	?=>>>,,X66
228<<%!xdh*?dh.?
 
 
 66x@@$$g&&(,,-=>> 	% 	
 	
 	

 "k!?
 
 
 #*"2"27K"H"HH{""$$$g{MBBBr   c                      t          d          )z9
        Extracts the unique user ID from `data`
        z6The provider must implement the `extract_uid()` method)r   r   datas     r   r>   zProvider.extract_uidb   s     "D
 
 	
r   c                     |S )z
        Extracts fields from `data` that will be stored in
        `SocialAccount`'s `extra_data` JSONField.

        :return: any JSON-serializable Python structure.
        r   rT   s     r   rD   zProvider.extract_extra_dataj   s	     r   c                     i S )a  
        Extracts fields from `data` that will be used to populate the
        `User` model in the `SOCIALACCOUNT_ADAPTER`'s `populate_user()`
        method.

        For example:

            {'first_name': 'John'}

        :return: dictionary of key-value pairs.
        r   rT   s     r   rE   zProvider.extract_common_fieldss   s	     	r   Fc                    ddl m} |rN|                                d |D             vr.|                     ||t	          |          d                     t                      }|D ]$}|                    | |j                  rd|_        %d S )Nr   )EmailAddressc                 @    g | ]}|j                                         S r   )r8   lower).0as     r   
<listcomp>z4Provider.cleanup_email_addresses.<locals>.<listcomp>   s"    *N*N*Nq17==??*N*N*Nr   T)r8   verifiedprimary)	allauth.account.modelsrY   r[   appendboolr   is_email_verifiedr8   r_   )r   r8   	addressesr9   rY   rN   addresss          r   rH   z Provider.cleanup_email_addresses   s    777777  	U[[]]*N*NI*N*N*NNN543G3GQUVVV   --  	( 	(G((w}== (#' 	( 	(r   c                     g S )z
        For example:

        [EmailAddress(email='john@example.com',
                      verified=True,
                      primary=True)]
        r   rT   s     r   rG   z Provider.extract_email_addresses   s	     	r   c                 l    t          | dd           }|s | j                            d          d         }|S )Npackage.r   )getattrr
   
rpartition)r   pkgs     r   get_packagezProvider.get_package   s:    c9d++ 	4.++C003C
r   r   )F)r	   r
   r   r   r   r   classmethodr   r#   r&   r+   r0   rR   r>   rD   rE   rH   rG   rn   r   r   r   r   r      s       DI    " " ["F F F F  2 2 27 7 74 4 4l
 
 
    ( ( ( (     [  r   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )ProviderAccountc                     || _         d S r   )r:   r)   s     r   r   zProviderAccount.__init__   s    %r   c                     d S r   r   r/   s    r   get_profile_urlzProviderAccount.get_profile_url       tr   c                     d S r   r   r/   s    r   get_avatar_urlzProviderAccount.get_avatar_url   ru   r   c                 j    | j                                         }t          |j        |j                  S )a7  
        Returns a dict containing an id and name identifying the
        brand. Useful when displaying logos next to accounts in
        templates.

        For most providers, these are identical to the provider. For
        OpenID however, the brand can derived from the OpenID identity
        url.
        )r   r    )r:   get_providerdictr   r    )r   r7   s     r   	get_brandzProviderAccount.get_brand   s.     <,,..x{7777r   c                 *    |                                  S r   )to_strr/   s    r   __str__zProviderAccount.__str__   s    {{}}r   c                 6    |                                  d         S )a  
        This did not use to work in the past due to py2 compatibility:

            class GoogleAccount(ProviderAccount):
                def __str__(self):
                    dflt = super(GoogleAccount, self).__str__()
                    return self.account.extra_data.get('name', dflt)

        So we have this method `to_str` that can be overridden in a conventional
        fashion, without having to worry about it.
        r    )r{   r/   s    r   r}   zProviderAccount.to_str   s     ~~''r   N)	r	   r
   r   r   rt   rw   r{   r~   r}   r   r   r   rq   rq      sn        & & &    8 8 8  ( ( ( ( (r   rq   N)django.core.exceptionsr   allauth.socialaccountr   r<   r   	Exceptionr   objectr   rq   r   r   r   <module>r      s    7 7 7 7 7 7 . . . . . . 5 5 5 5 5 5	 	 	 	 		 	 	 	T T T T Tv T T Tn&( &( &( &( &(f &( &( &( &( &(r   