diff --git a/api/urls.py b/api/urls.py index e3740d6..452f24d 100644 --- a/api/urls.py +++ b/api/urls.py @@ -12,5 +12,7 @@ urlpatterns = [ path('getsinglechat/', views.getsinglechat, name='api-getsinglechat'), path('chatnewmessage/', views.savenewchatmessage, name='api-savechatmessage'), # MIGRATION - path('migrateagencyusers/', views.migrateAgencyUsers, name="api-migrateagencyusers") + path('migrateagencyusers/', views.migrateAgencyUsers, name="api-migrateagencyusers"), + path('test/', views.test, name="api-test"), + ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index daa15b5..b7be5e0 100644 --- a/api/views.py +++ b/api/views.py @@ -1,3 +1,4 @@ +from django.shortcuts import redirect from rest_framework.views import APIView from rest_framework.response import Response #from rest_framework.permissions import IsAuthenticated # <-- Here @@ -86,4 +87,10 @@ def migrateAgencyUsers(request, pk): for user in User.objects.filter(profile__agency=Ag): if(len(user.email) > 0 and len(user.first_name) > 0 and len(user.last_name) > 0): datapackage.update({str(user.pk) : {"userid" : user.email, "displayname" : user.first_name + " " + user.last_name}}) - return JsonResponse(datapackage) \ No newline at end of file + return JsonResponse(datapackage) + + +from django.contrib.auth import login, logout +@api_view(['GET', ]) +def test(request): + return redirect('users-logout') diff --git a/chat/views.py b/chat/views.py index 95ba670..7d5a2dc 100644 --- a/chat/views.py +++ b/chat/views.py @@ -1,11 +1,11 @@ from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required -from channels_presence.models import Presence +#from channels_presence.models import Presence from django.http import HttpResponseRedirect,HttpResponse, JsonResponse from django.contrib.auth.models import User -from channels_presence.models import Room -from channels_presence.models import Presence -import channels.layers +#from channels_presence.models import Room +#from channels_presence.models import Presence +#import channels.layers from django.utils import timezone from .models import ChatRoom, ChatMessage from .forms import ChatAddChatRoom, ChatUpdateChatRoom diff --git a/digitaleagentur/__pycache__/settings.cpython-38.pyc b/digitaleagentur/__pycache__/settings.cpython-38.pyc index c2a23f5..3b397f4 100644 Binary files a/digitaleagentur/__pycache__/settings.cpython-38.pyc and b/digitaleagentur/__pycache__/settings.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/wsgi.cpython-38.pyc b/digitaleagentur/__pycache__/wsgi.cpython-38.pyc index f44f0f3..b88e319 100644 Binary files a/digitaleagentur/__pycache__/wsgi.cpython-38.pyc and b/digitaleagentur/__pycache__/wsgi.cpython-38.pyc differ diff --git a/digitaleagentur/asgi.py b/digitaleagentur/asgi.py index 27056c6..25e5156 100644 --- a/digitaleagentur/asgi.py +++ b/digitaleagentur/asgi.py @@ -2,11 +2,11 @@ ASGI entrypoint. Configures Django and then runs the application defined in the ASGI_APPLICATION setting. """ - +''' import os import django from channels.routing import get_default_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "digitaleagentur.settings") -django.setup() -application = get_default_application() \ No newline at end of file +''' +#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "digitaleagentur.settings") +#django.setup() +#application = get_default_application() \ No newline at end of file diff --git a/digitaleagentur/routing.py b/digitaleagentur/routing.py index f67ce3e..93b4e87 100644 --- a/digitaleagentur/routing.py +++ b/digitaleagentur/routing.py @@ -1,7 +1,9 @@ +''' from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import users.routing + application = ProtocolTypeRouter({ # Empty for now (http->django views is added by default) 'websocket': AuthMiddlewareStack( @@ -9,4 +11,6 @@ application = ProtocolTypeRouter({ users.routing.websocket_urlpatterns ) ), -}) \ No newline at end of file +}) + +''' \ No newline at end of file diff --git a/digitaleagentur/settings.py b/digitaleagentur/settings.py index b057e85..26fff5b 100644 --- a/digitaleagentur/settings.py +++ b/digitaleagentur/settings.py @@ -92,8 +92,8 @@ INSTALLED_APPS = [ 'django_user_agents', 'rest_framework', 'rest_framework.authtoken', - 'channels', - 'channels_presence', + #'channels', + #'channels_presence', 'simple_history', 'captcha', 'auditlog', @@ -115,6 +115,8 @@ MIDDLEWARE = [ ROOT_URLCONF = 'digitaleagentur.urls' +CSRF_COOKIE_SECURE = False + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -141,10 +143,11 @@ REST_FRAMEWORK = { #], } -#WSGI_APPLICATION = 'digitaleagentur.wsgi.application' +WSGI_APPLICATION = 'digitaleagentur.wsgi.application' ASGI_APPLICATION = "digitaleagentur.routing.application" +''' CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', @@ -153,7 +156,7 @@ CHANNEL_LAYERS = { }, }, } - +''' diff --git a/news/urls.py b/news/urls.py index 13be753..de5e098 100644 --- a/news/urls.py +++ b/news/urls.py @@ -17,5 +17,5 @@ urlpatterns = [ path('newsga/', permission_required('users.modulenews')(views.NewsGoToArchiv), name="news-gotoarchiv"), #path('standard//area', views.StandardArea, name="standard-area"), - #path('standard//task', views.StandardTask, name="standard-task") + #path('standard//task', views.StandardTask, name="standard-task") ] diff --git a/news/views.py b/news/views.py index 0835f29..a99dc64 100644 --- a/news/views.py +++ b/news/views.py @@ -1,3 +1,4 @@ +from django.http.response import JsonResponse from django.shortcuts import render, redirect from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView @@ -134,8 +135,3 @@ def NewsSingle(request, pk): return render(request, 'news/news_single.html', context) - - - - - diff --git a/requirements.txt b/requirements.txt index fe94bb4..38bc954 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,4 +36,5 @@ xhtml2pdf==0.2.5 django-simple-captcha==0.5.13 auditlog3==1.0.1 filetype==1.0.7 -Authlib==0.15.3 \ No newline at end of file +Authlib==0.15.3 +xmltodict==0.12.0 \ No newline at end of file diff --git a/users/mainwebsocket.py b/users/mainwebsocket.py_DELETE similarity index 99% rename from users/mainwebsocket.py rename to users/mainwebsocket.py_DELETE index ecd02c2..a1b0f08 100644 --- a/users/mainwebsocket.py +++ b/users/mainwebsocket.py_DELETE @@ -1,3 +1,4 @@ + import json from channels.generic.websocket import WebsocketConsumer from asgiref.sync import async_to_sync diff --git a/users/middleware/__pycache__/oauth.cpython-38.pyc b/users/middleware/__pycache__/oauth.cpython-38.pyc index dd9f9b0..af5e27b 100644 Binary files a/users/middleware/__pycache__/oauth.cpython-38.pyc and b/users/middleware/__pycache__/oauth.cpython-38.pyc differ diff --git a/users/middleware/oauth.py b/users/middleware/oauth.py index 00bbfe4..1630b00 100644 --- a/users/middleware/oauth.py +++ b/users/middleware/oauth.py @@ -1,3 +1,5 @@ +import re +from requests.api import request from authlib.integrations.base_client import OAuthError from authlib.integrations.django_client import OAuth from authlib.oauth2.rfc6749 import OAuth2Token @@ -5,8 +7,9 @@ from django.shortcuts import redirect from django.utils.deprecation import MiddlewareMixin from users.models import Agency, Profile from django.contrib.auth.models import User -from django.contrib.auth import login +from django.contrib.auth import login, logout from digitaleagentur import settings +import requests, json class OAuthMiddleware(MiddlewareMixin): @@ -33,7 +36,6 @@ class OAuthMiddleware(MiddlewareMixin): if not User.objects.filter(username = sub).exists(): pr = Profile(user=None, agency=Agency.objects.get(pk=1)) pr.save() - print(pr) activeuser = User.objects.create(username=sub, profile=pr) pr.user = activeuser pr.save() @@ -41,12 +43,20 @@ class OAuthMiddleware(MiddlewareMixin): activeuser = User.objects.get(username=sub) if activeuser is not None: + headers = { + 'Authorization': 'Bearer ' + request.session.get('token').get('access_token'), + 'Content-Type': 'application/json', + 'Accept': 'application/json', + } + data = {} + #response = requests.get("http://localhost:8080/apps/agency/getcurrentuser", data=data, headers=headers) + #print(response.text) login(request, activeuser) sso_client = self.oauth.register( settings.OAUTH_CLIENT_NAME, overwrite=True, **settings.OAUTH_CLIENT, update_token=update_token ) - if request.path.startswith('/users/oauth/callback'): + if request.path.startswith('/oauth/callback'): self.clear_session(request) request.session['token'] = sso_client.authorize_access_token(request) if self.get_current_user(sso_client, request) is not None: @@ -81,8 +91,6 @@ class OAuthMiddleware(MiddlewareMixin): try: res = sso_client.get(settings.OAUTH_CLIENT['userinfo_endpoint'], token=OAuth2Token(token)) if res.ok: - print("OK WE ARE HERE!") - print(res) #request.session['user'] = res.json() #request.session['user'] = res return True diff --git a/users/routing.py b/users/routing.py index d93fd31..1ec7fc8 100644 --- a/users/routing.py +++ b/users/routing.py @@ -1,3 +1,4 @@ +''' from django.urls import re_path from . import mainwebsocket @@ -7,4 +8,5 @@ websocket_urlpatterns = [ re_path(r'ws/groupchat/(?P\w+)/$', mainwebsocket.GroupChat, name="ws-groupchat"), re_path(r'ws/appchat/(?P\w+)/(?P\w+)/(?P\w+)/$', mainwebsocket.UsersChat, name="ws-appchat"), re_path(r'ws/', mainwebsocket.UsersConsumer, name="ws-default"), -] \ No newline at end of file +] +''' \ No newline at end of file diff --git a/users/signals.py b/users/signals.py index 8570cca..95f16b9 100644 --- a/users/signals.py +++ b/users/signals.py @@ -27,14 +27,24 @@ from asgiref.sync import async_to_sync from django.contrib.auth.decorators import login_required from datetime import timedelta from django.core.signals import request_started -from channels_presence.models import Room -from channels_presence.models import Presence -from channels_presence.signals import presence_changed +#from channels_presence.models import Room +#from channels_presence.models import Presence +#from channels_presence.signals import presence_changed from organizer.models import * from chat.models import ChatMessage from digitaleagentur.utils import * +from django.core.signals import request_finished +from django.dispatch import receiver + + +@receiver(request_finished) +def loginController(sender, **kwargs): + pass + + + def loadingFreeDays(plz, year): # Getting land file_path = os.path.join(settings.STATIC_ROOT, 'users/extra/plz_short.csv') @@ -544,7 +554,7 @@ def save_agjoin_prep(sender, instance, **kwargs): def receiver_function(sender, **kwargs): # DELETES ALL PRESENCE-OBJECTS LOWER THAN 15 MINUTES now_minus = datetime.datetime.now() - datetime.timedelta(minutes=2) - Presence.objects.filter(last_seen__lt=now_minus).delete() + #Presence.objects.filter(last_seen__lt=now_minus).delete() users = User.objects.all() @@ -559,17 +569,19 @@ def receiver_function(sender, **kwargs): # PRESENCE CHANGED +''' @receiver(signal=presence_changed) def update_presence_live(sender, **kwargs): channel_layer = channels.layers.get_channel_layer() async_to_sync(channel_layer.group_send)(str(kwargs["room"]), {'type' : 'update_presence_live'}) - +''' ''' ABWESENHEIT BERECHNUNG UND SPEICHERUNG DER NEUEN URLAUBSTAGE - VERWEIS AUF timemenagement.views ''' + @receiver(signal=post_save, sender=Absence) def save_newabsence(sender, instance, **kwargs): post_save.disconnect(save_newabsence, sender=sender) @@ -665,8 +677,8 @@ def save_newabsence(sender, instance, **kwargs): newnotification = UserNotification(touser=user, notificationtext="Neue Abwesenheit!", notificationtype="", elementid=instance.pk) newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Neue Abwesenheit für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Neue Abwesenheit für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) # Benutzer ist Vertreter if(user == instance.representator): if(user.usernotifications.absence_user_is_rep_mail): @@ -676,8 +688,8 @@ def save_newabsence(sender, instance, **kwargs): newnotification = UserNotification(touser=user, notificationtext="Neue Abwesenheitsvertretung!", notificationtype="", elementid=instance.pk) newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Sie wurden als Vertreter für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Sie wurden als Vertreter für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) # ABWESENHEIT GEÄNDERT else: @@ -698,8 +710,8 @@ def save_newabsence(sender, instance, **kwargs): newnotification = UserNotification(touser=user, notificationtext="Aktualisierte Abwesenheit!", notificationtype="", elementid=instance.pk) newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Abwesenheit für " + instance.user.first_name + " " + instance.user.last_name + " wurde aktualisiert!"}) + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Abwesenheit für " + instance.user.first_name + " " + instance.user.last_name + " wurde aktualisiert!"}) # Benutzer ist Vertreter if(user == instance.representator): @@ -710,8 +722,8 @@ def save_newabsence(sender, instance, **kwargs): newnotification = UserNotification(touser=user, notificationtext="Neue Abwesenheitsvertretung!", notificationtype="", elementid=instance.pk) newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Sie wurden als Vertreter für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | Sie wurden als Vertreter für " + instance.user.first_name + " " + instance.user.last_name + " eingetragen!"}) else: # Kein Urlaubsanspruch, dennoch prüfen ob bereits bestehende Arbeitstage involviert sind diff --git a/users/static/users/css/custom.css b/users/static/users/css/custom.css index 0523e77..9d8d38f 100644 --- a/users/static/users/css/custom.css +++ b/users/static/users/css/custom.css @@ -52,7 +52,6 @@ html h1 { } body{ background-color: #f8f9fc; - padding-top: 70px; } .modal-open {overflow-y: auto} diff --git a/users/templates/users/base.html b/users/templates/users/base.html index a6ca51e..848b123 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -14,33 +14,20 @@ - - - - - - - - - - - - @@ -50,63 +37,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - -
-