Use LdapManager call in change user details page

This commit is contained in:
PCoder 2019-02-24 15:29:40 +01:00
parent 3a867a4cd1
commit 3f7ab047a5

View file

@ -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):