Use LdapManager delete_user to delete the user's account
This commit is contained in:
parent
4e9493f198
commit
db4ffe7979
1 changed files with 21 additions and 18 deletions
39
dal/views.py
39
dal/views.py
|
@ -379,24 +379,27 @@ class DeleteAccount(View):
|
||||||
|
|
||||||
# Does the user exist?
|
# Does the user exist?
|
||||||
username = request.POST.get('username')
|
username = request.POST.get('username')
|
||||||
if not check_user_exists(username):
|
ldap_manager = LdapManager()
|
||||||
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Unknown user.' } )
|
user_exists, user_details = ldap_manager.check_user_exists(username)
|
||||||
|
if user_exists and request.user.username == username:
|
||||||
# Do user and password match?
|
# Do user and password match?
|
||||||
password = request.POST.get('password')
|
password = request.POST.get('password')
|
||||||
pwd = r'%s' % password
|
pwd = r'%s' % password
|
||||||
check = authenticate(request, username=username, password=pwd)
|
check = authenticate(request, username=username, password=pwd)
|
||||||
if check is None:
|
if check is None:
|
||||||
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Wrong password for user.' } )
|
return render(request, 'error.html',
|
||||||
|
{'urlname': urlname, 'service': service,
|
||||||
# Try to delete the user
|
'error': 'Wrong password for user.'})
|
||||||
with get_pool().next() as rpc:
|
result = ldap_manager.delete_user(username)
|
||||||
result = rpc.deleteuser.delete_user(username)
|
# User deleted
|
||||||
# User deleted
|
if result:
|
||||||
if result == True:
|
logout(request)
|
||||||
logout(request)
|
return render(request, 'deleteduser.html', {'user': username})
|
||||||
return render(request, 'deleteduser.html', { 'user': username } )
|
# User not deleted, got some kind of error
|
||||||
# User not deleted, got some kind of error
|
else:
|
||||||
|
return render(request, 'error.html',
|
||||||
|
{'urlname': urlname, 'service': service,
|
||||||
|
'error': result})
|
||||||
else:
|
else:
|
||||||
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': result } )
|
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': result } )
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue