mirror of
https://github.com/creyD/asiimov.git
synced 2026-06-14 18:02:22 +02:00
Added OpenID Support
This commit is contained in:
@@ -7,3 +7,8 @@ from .models import ItemType, Stickers, ItemInstance, Badge, Gamer
|
|||||||
class ItemTypeAdmin(admin.ModelAdmin):
|
class ItemTypeAdmin(admin.ModelAdmin):
|
||||||
list_display = ('paint_index', 'name', 'type', 'rarity', 'min_float', 'max_float', 'tradable')
|
list_display = ('paint_index', 'name', 'type', 'rarity', 'min_float', 'max_float', 'tradable')
|
||||||
list_editable = ()
|
list_editable = ()
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Gamer)
|
||||||
|
class Gamer(admin.ModelAdmin):
|
||||||
|
list_display = ('steamid', 'communityvisibilitystate', 'profilestate', 'personaname', 'commentpermission', 'timecreated', 'loccountrycode')
|
||||||
|
|||||||
@@ -107,4 +107,5 @@ class Offer(models.Model):
|
|||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def save_user_profile(sender, instance, **kwargs):
|
def save_user_profile(sender, instance, **kwargs):
|
||||||
instance.gamer.save()
|
if Gamer.objects.filter(system_user=instance).exists():
|
||||||
|
instance.gamer.save()
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ urlpatterns = [
|
|||||||
path('imprint', views.imprint, name='imprint'),
|
path('imprint', views.imprint, name='imprint'),
|
||||||
path('about', views.about, name='about'),
|
path('about', views.about, name='about'),
|
||||||
|
|
||||||
path('signup', views.signup, name='signup')
|
path('signup', views.signup, name='signup'),
|
||||||
|
path('signup_confirm', views.signup_confirm)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,9 +1,35 @@
|
|||||||
|
# Import the local models
|
||||||
from .models import Offer, Gamer
|
from .models import Offer, Gamer
|
||||||
|
# Django shortcuts for certain things
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
|
# For catching permission errors
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden
|
||||||
|
# For permitting only logged in users to see their private area
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
# For Steam Open ID handling
|
# For Steam Open ID handling
|
||||||
from oic.oic import Client
|
from urllib import parse
|
||||||
|
# For requesting the identification check
|
||||||
|
import requests
|
||||||
|
# For manually creating system users
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
# For getting the API interaction methods
|
||||||
|
from .steam_api import getUserInfo
|
||||||
|
# Import for manually logging in user after creation
|
||||||
|
from django.contrib.auth import login
|
||||||
|
|
||||||
|
|
||||||
|
# HELPER
|
||||||
|
def validate_steam_login(params):
|
||||||
|
steam_login_url_base = "https://steamcommunity.com/openid/login"
|
||||||
|
|
||||||
|
new_params = params.copy()
|
||||||
|
new_params["openid.mode"] = "check_authentication"
|
||||||
|
|
||||||
|
r = requests.post(steam_login_url_base, data=new_params)
|
||||||
|
|
||||||
|
if "is_valid:true" in r.text:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# STATIC PAGES
|
# STATIC PAGES
|
||||||
@@ -40,13 +66,44 @@ def search(request, filter):
|
|||||||
|
|
||||||
# USER SIGNUP
|
# USER SIGNUP
|
||||||
def signup(request):
|
def signup(request):
|
||||||
client = Client()
|
steam_openid_url = 'https://steamcommunity.com/openid/login'
|
||||||
issuer = client.discover('https://steamcommunity.com/openid/login')
|
u = {
|
||||||
#provider_info = client.provider_config(issuer)
|
'openid.ns': "http://specs.openid.net/auth/2.0",
|
||||||
context = {
|
'openid.identity': "http://specs.openid.net/auth/2.0/identifier_select",
|
||||||
'url': issuer
|
'openid.claimed_id': "http://specs.openid.net/auth/2.0/identifier_select",
|
||||||
|
'openid.mode': 'checkid_setup',
|
||||||
|
'openid.return_to': 'http://' + request.META['HTTP_HOST'] + '/signup_confirm',
|
||||||
|
'openid.realm': 'http://' + request.META['HTTP_HOST'] + ''
|
||||||
}
|
}
|
||||||
return render(request, 'core/signup.html', context)
|
|
||||||
|
query_string = parse.urlencode(u)
|
||||||
|
auth_url = steam_openid_url + '?' + query_string
|
||||||
|
return redirect(auth_url)
|
||||||
|
|
||||||
|
|
||||||
|
def signup_confirm(request):
|
||||||
|
if validate_steam_login(request.GET):
|
||||||
|
claimed_id = request.GET.get('openid.claimed_id')
|
||||||
|
claimed_id = claimed_id.split('/')[-1]
|
||||||
|
new_user, created = User.objects.get_or_create(username=claimed_id)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
info = getUserInfo(claimed_id)
|
||||||
|
Gamer.objects.create(
|
||||||
|
steamid=claimed_id,
|
||||||
|
system_user=new_user,
|
||||||
|
communityvisibilitystate=(True if info['response']['players'][0]['communityvisibilitystate'] == 3 else False),
|
||||||
|
profilestate=info['response']['players'][0]['profilestate'],
|
||||||
|
personaname=info['response']['players'][0]['personaname'],
|
||||||
|
profileurl=info['response']['players'][0]['profileurl'],
|
||||||
|
avatar=info['response']['players'][0]['avatar'],
|
||||||
|
commentpermission=info['response']['players'][0]['commentpermission'],
|
||||||
|
timecreated=info['response']['players'][0]['timecreated'] or None,
|
||||||
|
loccountrycode=info['response']['players'][0]['loccountrycode'] or None
|
||||||
|
)
|
||||||
|
login(request, new_user)
|
||||||
|
return redirect(me)
|
||||||
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
|
|
||||||
# USER AREA
|
# USER AREA
|
||||||
@@ -81,10 +138,10 @@ def profile(request, steamID):
|
|||||||
# PRIVATE AREA
|
# PRIVATE AREA
|
||||||
@login_required
|
@login_required
|
||||||
def me(request):
|
def me(request):
|
||||||
return render(request, 'core/profile.html', {'gamer': Gamer.object.get(system_user=request.User)})
|
return render(request, 'core/profile.html', {'gamer': Gamer.objects.get(system_user=request.user)})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def me_settings(request):
|
def me_settings(request):
|
||||||
dude = get_object_or_404(Gamer, system_user=request.User)
|
dude = get_object_or_404(Gamer, system_user=request.user)
|
||||||
return render(request, 'core/settings.html', {'gamer': dude})
|
return render(request, 'core/settings.html', {'gamer': dude})
|
||||||
|
|||||||
Reference in New Issue
Block a user