Skip to content
Snippets Groups Projects
Commit 2c7e444f authored by Christian Dresen's avatar Christian Dresen
Browse files

Added Password Change Function

parent a57d240a
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,8 @@
<div>
<br />
<form class="form-horizontal" method="POST" role="form">
<form class="form-horizontal" method="POST" action="/profile/change_password/" role="form">
{% csrf_token %}
<input type="hidden" name="action" value="change_pw">
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_old_pw">{% trans "Current Password" %}</label>
<div class=" col-sm-10 col-lg-10 ">
......@@ -23,7 +22,7 @@
<input class=" form-control" id="id_new_pw_confirm" name="new_pw_confirm" type="password" />
</div>
</div>
<div class="form-group">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button style="float: left" type="submit" formmethod="post" class="btn btn-primary">Change Password</button>
</div>
......
from django.conf.urls import url
from warpauth.views import main, login, reset_password, warp_food, profile
from warpauth.views import main, login, reset_password, profile
urlpatterns = [
# Authentication Pages
......@@ -10,6 +10,7 @@ urlpatterns = [
url(r'^reset_password/(?P<reset_hash>\w+)/$', reset_password.change_password, name='index'),
url(r'^profile/$', profile.index, name='index'),
url(r'^profile/change_password/$', profile.change_password, name='change_password'),
# Main Page
url(r'^$', main.index, name='index'),
......
import ldap
from warpzone import settings
pages = {'pages': [
{"link":"pizza", "name": "PizzaSheet"},
{"link":"about", "name": "About"},
]}
def __init_ldap():
ldapObject = ldap.initialize(settings.AUTH_LDAP_SERVER_URI)
ldapObject.bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
return ldapObject
def ldap_change_password(user,old_pw, new_pw):
ldapObject = __init_ldap()
try:
ldapObject.passwd_s(user,old_pw,new_pw)
return 1
except ldap.UNWILLING_TO_PERFORM as e:
if 'unwilling to verify old password' in e:
return -1
return 0
......@@ -2,11 +2,26 @@ from django.shortcuts import render
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed, HttpResponseNotFound
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from warpauth.models import LdapUser
from warpauth.util import *
##
# http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject
##
@login_required(login_url='/login/', redirect_field_name=None)
def index(request):
print(request.user.ldap_user.group_names)
pages['ldap_groups'] = request.user.ldap_user.group_names
#ldap_change_password(request.user.ldap_user.dn,"123456","12345")
return HttpResponse(render(request, 'warpauth/profile.html', pages))
@login_required(login_url='/login/', redirect_field_name=None)
def change_password(request):
if request.method != 'POST':
redirect("/")
print(request.POST)
return HttpResponse(render(request, 'warpauth/profile.html', pages))
\ No newline at end of file
......@@ -120,12 +120,15 @@ AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = "ldap://s1.dyhost.de"
AUTH_LDAP_BIND_DN = "cn=admin,dc=warpzone,dc=ms"
AUTH_LDAP_BIND_PASSWORD = "12345"
AUTH_LDAP_SERVER_URI = "ldap://s1.dyhost.de"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=User,dc=warpzone,dc=ms",
LDAP_USER_SEARCH_PATH = "ou=User,dc=warpzone,dc=ms"
AUTH_LDAP_USER_SEARCH = LDAPSearch(LDAP_USER_SEARCH_PATH,
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn", "email": "description"}
......@@ -153,3 +156,4 @@ AUTH_LDAP_GROUP_CACHE_TIMEOUT = 300
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment