From 58cbe7bf684112b4b8d72800b2dfe5ee4865d4a3 Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Sun, 25 Jul 2021 12:43:22 +0200 Subject: [PATCH] KLUK --- api/urls.py | 4 +- api/views.py | 9 +- chat/views.py | 8 +- .../__pycache__/settings.cpython-38.pyc | Bin 4704 -> 4620 bytes .../__pycache__/wsgi.cpython-38.pyc | Bin 583 -> 592 bytes digitaleagentur/asgi.py | 10 +- digitaleagentur/routing.py | 6 +- digitaleagentur/settings.py | 11 +- news/urls.py | 2 +- news/views.py | 6 +- requirements.txt | 3 +- ...inwebsocket.py => mainwebsocket.py_DELETE} | 1 + .../__pycache__/oauth.cpython-38.pyc | Bin 3384 -> 3569 bytes users/middleware/oauth.py | 18 +- users/routing.py | 4 +- users/signals.py | 38 +- users/static/users/css/custom.css | 1 - users/templates/users/base.html | 331 ++---------------- users/urls.py | 3 +- users/views.py | 50 +-- 20 files changed, 136 insertions(+), 369 deletions(-) rename users/{mainwebsocket.py => mainwebsocket.py_DELETE} (99%) 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 c2a23f55f3cbf5a8f6a568a90bef4a907e889440..3b397f4a5370ff6458318d1abacd98d9d6df9e48 100644 GIT binary patch delta 493 zcmZ9GO-~b16o%(srd8UMp%4OC6BZXXYtc`vJ?sh6j?^%a_2mvD1WcR z&5Fq|Bm21iHTm;I#HbVFn7|~S;u)S}3e$Ljmv|+D)P>j7jW=`;GeUueG-jb=4jG|3 z4B4tG7)3CTw+^HGFz5l^(L?00Ag4JjHhih!d4~y=dQkW;hUKcCPI^(KC`^iBh5DdT zT=pY*GJz63#wzt=jRx?Z25t7i_s!q%qY7Fb03Jo>L6MG0$Th|{Yppli;Q@0FU$UKCgafnX|0d9++d%UO2+3So^jm z?1RduqtxeP;iRm?!+mGZsyH7H+|^*hs|UB47Y$AE_BP!tX3Kg$pEELLGozP^8FyWa z#DBN0ne#?DT_`LVdV0mkFHvjy7V&D@55~B=7)EmwXHtLEe)mhb!*`*!sNDS(?(qdw KrgpggHo5|JCWt}+ delta 563 zcmYk3%TE(g6vpS?OkY$ivqGWNSF6@SeE=%HVC;**p{-M@a!`lb?=r0+MLM|94gLWp z#*E7@Y+Sl?mi`ljr7IH`?%kNU0H;-q=j41j-|ya>oaDTYe~qWAgM$N-7e8P9THP6y zq;Ea*f5bgA=as$tHuZTMlbEvNG>mCn#uZ$}46fliZr~!e9lcCU&Ek+}lht^~?iUo?|4sozF|o%yUSY|*L<_g%o??)OlZIg8;$E&#Dsd%nK)GV$+cTcByD>la-4-Xl$V!_0SE-^4#q9t$a|B~-qqPECbT%Us5mAxuP8M!C&nc|ximL5ucSD} c-7_R6B{Mydjango 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 dd9f9b0b6b87574e0671011af5a76a1705a6209e..af5e27b6586a80dbf7f4cbff1b1971cac7b41341 100644 GIT binary patch delta 1541 zcmZ8h&2QX96!*;fYrS4)^SQfe(yRc9tZ0)8dVxeir9l)SDg-T!e84#NH1Wn>Z{B#J zO%ts|IrPFInj1nDl`15pN`SbO3;zQ5;R4){5GoSfK;n&4nh0C-{AS+Ay!U(W`Qhvz zr@X86x})K9ZT0W>zZyUE=0*>27i%#|HD7&cN;2wGqWDT$$#h>Yc|A2U(>F`rNUhBF z?UFasYUcP($y;eHbA7ku?X;eGzL$;pW97b@HnMSlyyTs9BAfIlvnhXytgDM^>2x;Z z&y+%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~5T%Q!a{87J^W?a23+S4a>WQQ7{e5)wa9cOHoHnT%N5j0t>Xy5+T11+X%}a!sp?S z;LmVwTBF_~TgjkbF7nNiiF7D9vt_-0<+1~jqfig;Vo^dDT)!md$=me~^TAq;pI%K% z7(+;;66&W^HA&XbM3U2_4?_u~sYz5-UufqXChs-KFwE)e2t2rIGepn6)`^Dy2d>gL A)Bpeg 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - -
-