From aec394fc207279079c5c03e81278df5b3fd149f0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 23 Feb 2019 12:39:53 +0100 Subject: [PATCH] Nameko related changes --- dal/urls.py | 22 +++++++++++----------- dal/views.py | 9 ++++++--- nameko-func.py | 2 +- requirements.txt | 3 ++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/dal/urls.py b/dal/urls.py index f977499..6fb3c72 100644 --- a/dal/urls.py +++ b/dal/urls.py @@ -1,5 +1,5 @@ # The different URLs this service does use -from django.urls import path +#from django.conf.urls import url from django.conf.urls import url from django.contrib import admin @@ -7,14 +7,14 @@ from django.contrib import admin from .views import Register, ChangeData, ChangePassword, ResetPassword, DeleteAccount, Index, LogOut, ResetRequest urlpatterns = [ - path('register/', Register.as_view(), name="register"), - path('changedata/', ChangeData.as_view(), name="change_data"), - path('resetpassword/', ResetPassword.as_view(), name="reset_password"), - path('changepassword/', ChangePassword.as_view(), name="change_password"), - path('deleteaccount/', DeleteAccount.as_view(), name="account_delete"), - path('index/', Index.as_view(), name="index"), - path('logout/', LogOut.as_view(), name="logout"), - path('reset///', ResetRequest.as_view()), - path('reset/', ResetRequest.as_view(), name="reset"), - path('', Index.as_view(), name="index"), + url('register/', Register.as_view(), name="register"), + url('changedata/', ChangeData.as_view(), name="change_data"), + url('resetpassword/', ResetPassword.as_view(), name="reset_password"), + url('changepassword/', ChangePassword.as_view(), name="change_password"), + url('deleteaccount/', DeleteAccount.as_view(), name="account_delete"), + url('index/', Index.as_view(), name="index"), + url('logout/', LogOut.as_view(), name="logout"), + url('reset///', ResetRequest.as_view()), + url('reset/', ResetRequest.as_view(), name="reset"), + url('', Index.as_view(), name="index"), ] \ No newline at end of file diff --git a/dal/views.py b/dal/views.py index afd0241..dd176f3 100644 --- a/dal/views.py +++ b/dal/views.py @@ -10,6 +10,7 @@ from django.contrib.auth.tokens import PasswordResetTokenGenerator from django.core.mail import EmailMessage from .models import ResetToken from .forms import LoginForm +from django_nameko import get_pool # Imports for the extra stuff not in django @@ -224,11 +225,12 @@ class ResetPassword(View): return render(request, 'resetpassword.html') def post(self, request): + l = LDAP() urlname = 'reset_password' service = 'send a password reset request' user = request.POST.get('user') # First, check if the user exists - if not check_user_exists(user): + if not l.check_user_exists(user): return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'The user does not exist.' } ) # user exists, so try to get email with get_pool().next() as rpc: @@ -250,7 +252,7 @@ class ResetPassword(View): # getting epoch for the time now in UTC to spare us headache with timezones creationtime = int(datetime.utcnow().timestamp()) # Construct the data for the email - email_from = 'Userservice at ungleich <%s>' % config['EMAIL']['EMAILFROM'] + email_from = 'Userservice at ungleich <%s>' % 'support@ungleich.ch' to = ['%s <%s>' % (user, email)] subject = 'Password reset request for %s' % user link = self.build_reset_link(user, creationtime) @@ -421,13 +423,14 @@ class DeleteAccount(View): # Reads the filled out form def post(self, request): + l = LDAP() # Variables for error page urlname = 'account_delete' service = 'delete an account' # Does the user exist? username = request.POST.get('username') - if not check_user_exists(username): + if not l.check_user_exists(username): return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Unknown user.' } ) # Do user and password match? diff --git a/nameko-func.py b/nameko-func.py index d43a4bc..0d97943 100644 --- a/nameko-func.py +++ b/nameko-func.py @@ -346,5 +346,5 @@ class Log(object): def event_handler_ldap(self, payload): f = open(self.ldaplog, mode='a', encoding='utf-8') f.write(payload) - f.close + f.close() diff --git a/requirements.txt b/requirements.txt index 3f3ab68..1e6d2d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -django +django==1.11.20 django-auth-ldap python-ldap django-bootstrap3 django-filter==2.1.0 python-decouple +git+https://github.com/pcoder/django-nameko.git#egg=django-nameko \ No newline at end of file