From 889fdd924f8a935d8fea9c8cefd1270fa6f72245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Nov=C3=BD?= <github-lnovy@krtek.net> Date: Tue, 30 Jun 2015 06:47:22 +0000 Subject: [PATCH] PirateID support --- helios_auth/auth_systems/__init__.py | 3 +- helios_auth/auth_systems/pirateid.py | 55 ++++++++++++++++++++++++++++ settings.py | 7 +++- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 helios_auth/auth_systems/pirateid.py diff --git a/helios_auth/auth_systems/__init__.py b/helios_auth/auth_systems/__init__.py index 202fe95..8c0be51 100644 --- a/helios_auth/auth_systems/__init__.py +++ b/helios_auth/auth_systems/__init__.py @@ -1,7 +1,7 @@ AUTH_SYSTEMS = {} -import twitter, password, cas, facebook, google, yahoo, linkedin +import twitter, password, cas, facebook, google, yahoo, linkedin, pirateid AUTH_SYSTEMS['twitter'] = twitter AUTH_SYSTEMS['linkedin'] = linkedin AUTH_SYSTEMS['password'] = password @@ -9,6 +9,7 @@ AUTH_SYSTEMS['cas'] = cas AUTH_SYSTEMS['facebook'] = facebook AUTH_SYSTEMS['google'] = google AUTH_SYSTEMS['yahoo'] = yahoo +AUTH_SYSTEMS['pirateid'] = pirateid # not ready #import live diff --git a/helios_auth/auth_systems/pirateid.py b/helios_auth/auth_systems/pirateid.py new file mode 100644 index 0000000..dade34d --- /dev/null +++ b/helios_auth/auth_systems/pirateid.py @@ -0,0 +1,55 @@ +""" +Yahoo Authentication + +""" + +from django.http import * +from django.core.mail import send_mail +from django.conf import settings + +import sys, os, cgi, urllib, urllib2, re +from xml.etree import ElementTree + +from openid import view_helpers + +# some parameters to indicate that status updating is not possible +STATUS_UPDATES = False + +# display tweaks +LOGIN_MESSAGE = "Log in with my PirateID" +OPENID_ENDPOINT = 'https://openid.pirati.cz' + +def get_auth_url(request, redirect_url): + request.session['pirateid_redirect_url'] = redirect_url + url = view_helpers.start_openid(request.session, OPENID_ENDPOINT, redirect_url, redirect_url) + return url + +def get_user_info_after_auth(request): + data = view_helpers.finish_openid(request.session, request.GET, request.session['pirateid_redirect_url']) + + return {'type' : 'pirateid', 'user_id': data['ax']['email'][0], 'name': data['ax']['fullname'][0], 'info': {'email': data['ax']['email'][0]}, 'token':{}} + +def do_logout(user): + """ + logout of Yahoo + """ + return None + +def update_status(token, message): + """ + simple update + """ + pass + +def send_message(user_id, user_name, user_info, subject, body): + """ + send email to yahoo user, user_id is email for yahoo and other openID logins. + """ + send_mail(subject, body, settings.SERVER_EMAIL, ["%s <%s>" % (user_name, user_id)], fail_silently=False) + +def check_constraint(constraint, user_info): + """ + for eligibility + """ + pass + diff --git a/settings.py b/settings.py index eab44a0..335948d 100644 --- a/settings.py +++ b/settings.py @@ -76,7 +76,7 @@ MEDIA_URL = '' STATIC_URL = '/media/' # Make this unique, and don't share it with anybody. -SECRET_KEY = get_from_env('SECRET_KEY', 'replaceme') +SECRET_KEY = get_from_env('SECRET_KEY', 'replacemesadfasdfasdf') # Secure Stuff if (get_from_env('SSL', '0') == '1'): @@ -160,7 +160,7 @@ LOGOUT_ON_CONFIRMATION = True # The two hosts are here so the main site can be over plain HTTP # while the voting URLs are served over SSL. -URL_HOST = get_from_env("URL_HOST", "http://localhost:8000").rstrip("/") +URL_HOST = get_from_env("URL_HOST", "http://helios-server-lnovy.c9.io").rstrip("/") # IMPORTANT: you should not change this setting once you've created # elections, as your elections' cast_url will then be incorrect. @@ -260,3 +260,6 @@ djcelery.setup_loader() # for testing TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner' # this effectively does CELERY_ALWAYS_EAGER = True + +SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer' + -- GitLab