diff --git a/account/cbase_members.py b/account/cbase_members.py index 5845382..47dcbfa 100644 --- a/account/cbase_members.py +++ b/account/cbase_members.py @@ -60,10 +60,8 @@ class MemberValues(object): Save the values back to the LDAP server. """ dn = "uid=%s,ou=crew,dc=c-base,dc=org" % self._username - print 'setting dn=', dn - # TODO: Use settings for url - l = ldap.initialize("ldap://lea.cbrp3.c-base.org:389/") + l = ldap.initialize(settings.CBASE_LDAP_URL) l.simple_bind_s(dn, self._password) mod_attrs = [] @@ -83,6 +81,18 @@ class MemberValues(object): print "modattrs: ",mod_attrs result = l.modify_s(dn, mod_attrs) print "result is: ", result + l.unbind_s() + + def change_password(self, new_password): + """ + Change the password of the member. + You do not need to call save() after calling change_password(). + """ + l = ldap.initialize(settings.CBASE_LDAP_URL) + user_dn = self._get_bind_dn() + l.simple_bind_s(user_dn, self._password) + l.passwd_s(user_dn, self._password, new_password) + l.unbind_s() def to_dict(self): result = {} @@ -119,3 +129,4 @@ class MemberValues(object): print "result is: ", result # TODO: if len(result)==0 return result[0][1] + session.unbind_s() diff --git a/account/forms.py b/account/forms.py index f50d10f..01b5f24 100644 --- a/account/forms.py +++ b/account/forms.py @@ -61,11 +61,36 @@ class WlanPresenceForm(forms.Form): class PasswordForm(forms.Form): + old_password = forms.CharField(max_length=255, widget=forms.PasswordInput, + label=_('Old password'), + help_text=_('Enter your current password here.')) password1 = forms.CharField(max_length=255, widget=forms.PasswordInput, label=_('New password')) password2 = forms.CharField(max_length=255, widget=forms.PasswordInput, label=_('Repeat password')) + def __init__(self, *args, **kwargs): + self._request = kwargs.pop('request', None) + super(PasswordForm, self).__init__(*args, **kwargs) + + def clean(self): + cleaned_data = super(PasswordForm, self).clean() + old_password = cleaned_data.get('old_password') + username = self._request.user.username + user = authenticate(username=username, password=old_password) + + if not user or not user.is_active: + raise forms.ValidationError(_('The old password was incorrect.'), + code='old_password_wrong') + + password1 = cleaned_data.get('password1') + password2 = cleaned_data.get('password2') + if password1 != password2: + raise forms.ValidationError( + _('The new passwords were not identical.'), + code='not_identical') + return cleaned_data + class RFIDForm(forms.Form): rfid = forms.CharField(max_length=255, label=_('Your RFID'), diff --git a/account/templates/start.html b/account/templates/home.html similarity index 87% rename from account/templates/start.html rename to account/templates/home.html index c2b7861..f8f2aaa 100644 --- a/account/templates/start.html +++ b/account/templates/home.html @@ -25,6 +25,14 @@ +