This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth.provider import OAuthProvider
class FiveHundredPxAccount(ProviderAccount):
def get_profile_url(self):
return "https://500px.com/%s" % self.account.extra_data.get("username")
def get_avatar_url(self):
return self.account.extra_data.get("userpic_url")
def to_str(self):
dflt = super(FiveHundredPxAccount, self).to_str()
name = self.account.extra_data.get("fullname", dflt)
return name
class FiveHundredPxProvider(OAuthProvider):
id = "500px"
name = "500px"
package = "allauth.socialaccount.providers.fivehundredpx"
account_class = FiveHundredPxAccount
def get_default_scope(self):
return []
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
return dict(
username=data.get("username"),
email=data.get("email"),
first_name=data.get("firstname"),
last_name=data.get("lastname"),
)
provider_classes = [FiveHundredPxProvider]

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
from allauth.socialaccount.tests import OAuthTestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import FiveHundredPxProvider
class FiveHundredPxTests(OAuthTestsMixin, TestCase):
provider_id = FiveHundredPxProvider.id
def get_mocked_response(self):
return [
MockedResponse(
200,
"""{
"user": {
"id": 5751454,
"username": "testuser",
"firstname": "Test",
"lastname": "User",
"birthday": null,
"sex": 0,
"city": "San Francisco",
"state": "California",
"country": "United States",
"registration_date": "2015-12-12T03:20:31-05:00",
"about": "About me.",
"usertype": 0,
"fotomoto_on": true,
"locale": "en",
"show_nude": false,
"allow_sale_requests": 1,
"fullname": "Test User",
"userpic_url": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1",
"userpic_https_url": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1",
"cover_url": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/cover_2048.jpg?7",
"upgrade_status": 2,
"store_on": true,
"photos_count": 68,
"galleries_count": 2,
"affection": 1888,
"in_favorites_count": 340,
"friends_count": 181,
"followers_count": 150,
"analytics_code": null,
"invite_pending": false,
"invite_accepted": false,
"email": "test@example.com",
"shadow_email": "test@example.com",
"upload_limit": null,
"upload_limit_expiry": "2016-12-01T13:33:55-05:00",
"upgrade_type": 2,
"upgrade_status_expiry": "2017-05-27",
"auth": {
"facebook": 0,
"twitter": 0,
"google_oauth2": 0
},
"presubmit_for_licensing": null,
"avatars": {
"default": {
"http": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1",
"https": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1"
},
"large": {
"http": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/2.jpg?1",
"https": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/2.jpg?1"
},
"small": {
"http": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1",
"https": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/1.jpg?1"
},
"tiny": {
"http": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/4.jpg?1",
"https": "https://pacdn.500px.org/10599609/8e20991262c468a866918dcbe2f7e9a30e2c2c9c/4.jpg?1"
}
}
}
}""",
)
] # noqa

View File

@@ -0,0 +1,6 @@
from allauth.socialaccount.providers.oauth.urls import default_urlpatterns
from .provider import FiveHundredPxProvider
urlpatterns = default_urlpatterns(FiveHundredPxProvider)

View File

@@ -0,0 +1,42 @@
import json
from allauth.socialaccount.providers.oauth.client import OAuth
from allauth.socialaccount.providers.oauth.views import (
OAuthAdapter,
OAuthCallbackView,
OAuthLoginView,
)
from .provider import FiveHundredPxProvider
API_BASE = "https://api.500px.com/v1"
class FiveHundredPxAPI(OAuth):
"""
Verifying 500px credentials
"""
url = API_BASE + "/users"
def get_user_info(self):
return json.loads(self.query(self.url))["user"]
class FiveHundredPxOAuthAdapter(OAuthAdapter):
provider_id = FiveHundredPxProvider.id
request_token_url = API_BASE + "/oauth/request_token"
access_token_url = API_BASE + "/oauth/access_token"
authorize_url = API_BASE + "/oauth/authorize"
def complete_login(self, request, app, token, response):
client = FiveHundredPxAPI(
request, app.client_id, app.secret, self.request_token_url
)
extra_data = client.get_user_info()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth_login = OAuthLoginView.adapter_view(FiveHundredPxOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(FiveHundredPxOAuthAdapter)