# Path: bundestagger/account/auth.py
# def login(request, openid):
#     try:
#         user = User.objects.get(openid=openid)
#     except User.DoesNotExist:
#         user = User.objects.create(openid=openid, username="Nutzer")
#         user.username = "%s%d" % (user.username,user.id)
#         user.save()
#     request.session["bundesuser"] = user
#     return True
# 
# def logout(request):
#     if "bundesuser" in request.session:
#         del request.session["bundesuser"]
#     if "openids" in request.session:
#         del request.session["openids"]
#     if "openid" in request.session:
#         del request.session["openid"]


from django.http import HttpResponseRedirect
from django.conf import settings
from django_openid.consumer import SessionConsumer
from django.contrib import messages
from bundestagger.account.auth import login, logout
# -*- coding: utf-8 -*-


class BundesOpenidConsumer(SessionConsumer):
    session_key = 'openid'
    openid_required_message = 'Gib eine OpenID ein'
    xri_disabled_message = 'i-names werden nicht unterstützt'
    openid_invalid_message = 'Die OpenID ist nicht gültig'
    request_cancelled_message = 'Die Anfrage wurde abgebrochen'
    message_loggedin = "Erfolgreich eingeloggt"
    message_loggedout = "Erfolgreich ausgeloggt"
    failure_message = 'Fehler: %s'
    setup_needed_message = 'Setup benötigt'
    sign_next_param = False
    salt_next = '07n98kpajapd290?(H"N=)(czar3)' # Adds extra saltiness to the ?next= salt
    xri_enabled = False
    on_complete_url = None
    trust_root = settings.SITE_DOMAIN # If None, full URL to endpoint is used
    logo_path = None # Path to the OpenID logo, as used by the login view
    
    def show_error(self, request, message, exception=None):
        messages.error(request, message)
        return HttpResponseRedirect("/")


# Path: bundestagger/account/auth.py
# def login(request, openid):
#     try:
#         user = User.objects.get(openid=openid)
#     except User.DoesNotExist:
#         user = User.objects.create(openid=openid, username="Nutzer")
#         user.username = "%s%d" % (user.username,user.id)
#         user.save()
#     request.session["bundesuser"] = user
#     return True
# 
# def logout(request):
#     if "bundesuser" in request.session:
#         del request.session["bundesuser"]
#     if "openids" in request.session:
#         del request.session["openids"]
#     if "openid" in request.session:
#         del request.session["openid"]


# Path: bundestagger/account/openid_consumer.py
from django.http import HttpResponseRedirect
from django.conf import settings
from django_openid.consumer import SessionConsumer
from django.contrib import messages
from bundestagger.account.auth import login, logout

# -*- coding: utf-8 -*-


class BundesOpenidConsumer(SessionConsumer):
    session_key = 'openid'
    openid_required_message = 'Gib eine OpenID ein'
    xri_disabled_message = 'i-names werden nicht unterstützt'
    openid_invalid_message = 'Die OpenID ist nicht gültig'
    request_cancelled_message = 'Die Anfrage wurde abgebrochen'
    message_loggedin = "Erfolgreich eingeloggt"
    message_loggedout = "Erfolgreich ausgeloggt"
    failure_message = 'Fehler: %s'
    setup_needed_message = 'Setup benötigt'
    sign_next_param = False
    salt_next = '07n98kpajapd290?(H"N=)(czar3)' # Adds extra saltiness to the ?next= salt
    xri_enabled = False
    on_complete_url = None
    trust_root = settings.SITE_DOMAIN # If None, full URL to endpoint is used
    logo_path = None # Path to the OpenID logo, as used by the login view
    
    def show_error(self, request, message, exception=None):
        messages.error(request, message)
        return HttpResponseRedirect("/")


    def show_message(self, request, title, message):