| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.mailru.views import MailRuOAuth2Adapter |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class MailRuAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
return self.account.extra_data.get("link") |
| 11 |
|
| 12 |
def get_avatar_url(self): |
| 13 |
ret = None |
| 14 |
if self.account.extra_data.get("has_pic"): |
| 15 |
pic_big_url = self.account.extra_data.get("pic_big") |
| 16 |
pic_small_url = self.account.extra_data.get("pic_small") |
| 17 |
if pic_big_url: |
| 18 |
return pic_big_url |
| 19 |
elif pic_small_url: |
| 20 |
return pic_small_url |
| 21 |
else: |
| 22 |
return ret |
| 23 |
|
| 24 |
|
| 25 |
class MailRuProvider(OAuth2Provider): |
| 26 |
id = "mailru" |
| 27 |
name = "Mail.RU" |
| 28 |
account_class = MailRuAccount |
| 29 |
oauth2_adapter_class = MailRuOAuth2Adapter |
| 30 |
|
| 31 |
def extract_uid(self, data): |
| 32 |
return data["uid"] |
| 33 |
|
| 34 |
def extract_common_fields(self, data): |
| 35 |
return dict( |
| 36 |
email=data.get("email"), |
| 37 |
last_name=data.get("last_name"), |
| 38 |
username=data.get("nick"), |
| 39 |
first_name=data.get("first_name"), |
| 40 |
) |
| 41 |
|
| 42 |
|
| 43 |
provider_classes = [MailRuProvider] |