update authentication

This commit is contained in:
2020-10-14 17:40:38 +00:00
parent 847f2f6e83
commit c36bf35373
4 changed files with 33 additions and 12 deletions

View File

@@ -19,3 +19,23 @@ def authenticated_user(view_func):
return redirect('home') return redirect('home')
return wrapper_func return wrapper_func
def ep_unauthenticated_user(view_func):
def wrapper_func(request, *args, **kwargs):
if request.user.is_authenticated:
return None, None
else:
return view_func(request, *args, **kwargs)
return wrapper_func
def ep_authenticated_user(view_func):
def wrapper_func(request, *args, **kwargs):
if request.user.is_authenticated:
return view_func(request, *args, **kwargs)
else:
return None, None
return wrapper_func

View File

@@ -5,6 +5,9 @@ import urllib.parse
from etherpad_lite import EtherpadLiteClient, EtherpadException from etherpad_lite import EtherpadLiteClient, EtherpadException
import logging
logger = logging.getLogger(__name__)
SERVER_URL = settings.ETHERPAD_CLIENT["exturl"] SERVER_URL = settings.ETHERPAD_CLIENT["exturl"]
@@ -22,7 +25,8 @@ def get_ep_client():
) )
group = epc.createGroupIfNotExistsFor(groupMapper="fet") group = epc.createGroupIfNotExistsFor(groupMapper="fet")
except Exception as e: except Exception as e:
raise e logger.info("Can't get connection to Etherpad Server. Error: {}".format(e))
return None, None
return epc, group return epc, group
@@ -32,7 +36,7 @@ def __checkPadExists(padID=None):
return False return False
epc, group = get_ep_client() epc, group = get_ep_client()
if not epc: if not epc or not group:
return None return None
try: try:
@@ -64,12 +68,6 @@ def createPadifNotExists(padID):
return padID return padID
def getReadOnlyID(padID):
epc, group = get_ep_client()
url = epc.getReadOnlyID(padID=group["groupID"] + "$" + padID)['readOnlyID']
return url
def getPadHTML(padID): def getPadHTML(padID):
epc, group = get_ep_client() epc, group = get_ep_client()
text = epc.getHTML(padID=group["groupID"] + "$" + padID)["html"] text = epc.getHTML(padID=group["groupID"] + "$" + padID)["html"]
@@ -87,7 +85,7 @@ def get_pad_link(padID):
return "#" return "#"
epc, group = get_ep_client() epc, group = get_ep_client()
if epc: if epc:
return urllib.parse.urljoin(SERVER_URL, 'p/' + group["groupID"] + '$' + str(padID)) return urllib.parse.urljoin(SERVER_URL, 'p/' + group["groupID"] + '$' + str(padID))
return "" return ""

View File

@@ -1,12 +1,14 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from .api import get_ep_client from .api import get_ep_client
from authentications.decorators import authenticated_user from authentications.decorators import ep_authenticated_user
@authenticated_user @ep_authenticated_user
def __get_ep_sessionid(request): def __get_ep_sessionid(request):
epc, group = get_ep_client() epc, group = get_ep_client()
if not epc or not group:
return None, None
author = epc.createAuthorIfNotExistsFor( author = epc.createAuthorIfNotExistsFor(
name=str(request.user), name=str(request.user),

View File

@@ -49,6 +49,8 @@
Start: {{ post.event_start }}<br> Start: {{ post.event_start }}<br>
Ende: {{ post.event_end }}<br> Ende: {{ post.event_end }}<br>
{% if request.user.is_authenticated %}
{% if post.has_agenda %} {% if post.has_agenda %}
<a href="{{ ep_agenda_link }}">Agenda</a><br> <a href="{{ ep_agenda_link }}">Agenda</a><br>
{% endif %} {% endif %}
@@ -57,7 +59,6 @@
<a href="{{ ep_protocol_link }}">Protokoll</a> <a href="{{ ep_protocol_link }}">Protokoll</a>
{% endif %} {% endif %}
{% if request.user.is_authenticated %}
<br>------<br> <br>------<br>
<a href="{% url "admin:posts_news_change" post.id %}">Bearbeiten</a> <a href="{% url "admin:posts_news_change" post.id %}">Bearbeiten</a>
{% endif %} {% endif %}