| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.app_settings import STORE_TOKENS |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.eveonline.views import EveOnlineOAuth2Adapter |
| 6 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 7 |
|
| 8 |
|
| 9 |
class EveOnlineAccount(ProviderAccount): |
| 10 |
def get_profile_url(self): |
| 11 |
return "https://gate.eveonline.com/Profile/{char_name}".format( |
| 12 |
char_name=self.account.extra_data.get("CharacterName") |
| 13 |
) |
| 14 |
|
| 15 |
def get_avatar_url(self): |
| 16 |
return ("https://image.eveonline.com/Character/{char_id}_128.jpg").format( |
| 17 |
char_id=self.account.extra_data.get("CharacterID", 1) |
| 18 |
) |
| 19 |
|
| 20 |
def to_str(self): |
| 21 |
dflt = super().to_str() |
| 22 |
return next( |
| 23 |
value |
| 24 |
for value in ( |
| 25 |
self.account.extra_data.get("CharacterName", None), |
| 26 |
self.account.extra_data.get("CharacterID", None), |
| 27 |
dflt, |
| 28 |
) |
| 29 |
if value is not None |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
class EveOnlineProvider(OAuth2Provider): |
| 34 |
id = "eveonline" |
| 35 |
name = "EVE Online" |
| 36 |
account_class = EveOnlineAccount |
| 37 |
oauth2_adapter_class = EveOnlineOAuth2Adapter |
| 38 |
|
| 39 |
def get_default_scope(self): |
| 40 |
scopes = [] |
| 41 |
if STORE_TOKENS: |
| 42 |
scopes.append("publicData") |
| 43 |
return scopes |
| 44 |
|
| 45 |
def extract_uid(self, data): |
| 46 |
return str(data["CharacterOwnerHash"]) |
| 47 |
|
| 48 |
def extract_common_fields(self, data): |
| 49 |
return dict(name=data.get("CharacterName")) |
| 50 |
|
| 51 |
|
| 52 |
provider_classes = [EveOnlineProvider] |