From 3f7ab047a50e69aa3c520c74fc9eb628812a0e78 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 24 Feb 2019 15:29:40 +0100 Subject: [PATCH] Use LdapManager call in change user details page --- dal/views.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/dal/views.py b/dal/views.py index a1ff4a2..a4e02f0 100644 --- a/dal/views.py +++ b/dal/views.py @@ -101,16 +101,30 @@ class ChangeData(View): if not request.user.is_authenticated: return render(request, 'mustbeloggedin.html') user = request.user - login(request, user) - # get basic data (firstname, lastname, email) - with get_pool().next() as rpc: - (state, firstname, lastname, email) = rpc.getuserdata.get_data(str(request.user)) - # If it throws an error, the errormessage gets put into firstname.. not great naming, but works best this way - if state == "error": - return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': firstname } ) - # The template puts the old data as standard in the fields + + ldap_manager = LdapManager() + user_exists, entries = ldap_manager.check_user_exists( + uid=user.username, + is_customer=True, + attributes=['uid', 'givenName', 'sn', 'email'] + ) + + if user_exists: + return render( + request, + 'changeuserdata.html', + { 'user': user.username, + 'firstname': entries[0].givenName + if entries[0].givenName.value is not None else '', + 'lastname': entries[0].sn + if entries[0].sn.value is not None else '', + 'email': entries[0].email + if entries[0].email.value is not None else ''} + ) else: - return render(request, 'changeuserdata.html', { 'user': str(request.user), 'firstname': firstname, 'lastname': lastname, 'email': email } ) + return render(request, 'error.html', + {'urlname': urlname, 'service': service, + 'error': request.user.username}) # get the change request def post(self, request):