
    h                         d dl mZ d dlmZ d dlmZ dej                  v rd dlmZ d dl	m
Z
 d dlmZ d dlmZ  G d	 d
ej                        Z G d dee      Zy)    )settings)HttpRequest)serializerszallauth.socialaccount)complete_social_login)SocialToken)
OAuthError)SocialConnectMixinc                   b    e Zd Z ej                         Z ej                         Zd Zd Zd Z	y)TwitterLoginSerializerc                 t    | j                   j                  d      }t        |t              s|j                  }|S )Nrequest)contextget
isinstancer   _request)selfr   s     b/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/dj_rest_auth/social_serializers.py_get_requestz#TwitterLoginSerializer._get_request   s0    ,,""9-';/&&G    c                 ^    | j                         }|j                  ||||      }||_        |S )a  
        :param adapter: allauth.socialaccount Adapter subclass.
            Usually OAuthAdapter or Auth2Adapter
        :param app: `allauth.socialaccount.SocialApp` instance
        :param token: `allauth.socialaccount.SocialToken` instance
        :param response: Provider's response for OAuth1. Not used in the
        :returns: A populated instance of the
            `allauth.socialaccount.SocialLoginView` instance
        )response)r   complete_logintoken)r   adapterappr   r   r   social_logins          r   get_social_loginz'TwitterLoginSerializer.get_social_login   sA     ##%--S% . 
 #r   c                    | j                   j                  d      }| j                         }|st        j                  d      t        |dd       }|st        j                  d       ||      }|j                         j                  |      }|j                  d      }|j                  d      }||d|j                  d<   t        ||	      }	||	_
        	 | j                  |||	|      }
t        ||
       |
j                  s#|
j!                          |
j#                  |d
       |
j$                  j&                  |d<   |S # t        $ r#}t        j                  t        |            d }~ww xY w)Nviewz2View is not defined, pass it as a context variableadapter_classzDefine adapter_class in viewaccess_tokentoken_secret)oauth_tokenoauth_token_secretz"oauth_api.twitter.com_access_token)r   r"   T)connectuser)r   r   r   r   ValidationErrorgetattrget_providerget_appsessionr   r   r   r   r   stris_existinglookupsaveaccountr&   )r   attrsr   r   r    r   r   r!   r"   r   logines               r   validatezTwitterLoginSerializer.validate,   sX   ||'##%--D   ot<--.LMM(""$,,W5yy0yy0 (".A
<= ,\J		6))'3|LE!'51   LLNJJwJ-**f  	6--c!f55	6s    E 	E-
E((E-N)
__name__
__module____qualname__r   	CharFieldr!   r"   r   r   r4    r   r   r   r      s1    (;((*L(;((*L$%r   r   c                       e Zd Zy)TwitterConnectSerializerN)r5   r6   r7   r9   r   r   r;   r;   T   s    r   r;   N)django.confr   django.httpr   rest_frameworkr   INSTALLED_APPSallauth.socialaccount.helpersr   allauth.socialaccount.modelsr   ,allauth.socialaccount.providers.oauth.clientr   %dj_rest_auth.registration.serializersr	   
Serializerr   r;   r9   r   r   <module>rE      sO      # &
 h555C8GHA[33 AH	13I 	r   