Use LdapManager call in change user details page
This commit is contained in:
parent
3a867a4cd1
commit
3f7ab047a5
1 changed files with 23 additions and 9 deletions
32
dal/views.py
32
dal/views.py
|
@ -101,16 +101,30 @@ class ChangeData(View):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return render(request, 'mustbeloggedin.html')
|
return render(request, 'mustbeloggedin.html')
|
||||||
user = request.user
|
user = request.user
|
||||||
login(request, user)
|
|
||||||
# get basic data (firstname, lastname, email)
|
ldap_manager = LdapManager()
|
||||||
with get_pool().next() as rpc:
|
user_exists, entries = ldap_manager.check_user_exists(
|
||||||
(state, firstname, lastname, email) = rpc.getuserdata.get_data(str(request.user))
|
uid=user.username,
|
||||||
# If it throws an error, the errormessage gets put into firstname.. not great naming, but works best this way
|
is_customer=True,
|
||||||
if state == "error":
|
attributes=['uid', 'givenName', 'sn', 'email']
|
||||||
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': firstname } )
|
)
|
||||||
# The template puts the old data as standard in the fields
|
|
||||||
|
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:
|
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
|
# get the change request
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
|
Loading…
Reference in a new issue