Commits

Zhang Huangbin  committed 65f2a71

Sync templates.

  • Participants
  • Parent commits 650e4cf

Comments (0)

Files changed (4)

File libs/ldaplib/core.py

 
 import os, sys, time
 import web
-import ldap
+import ldap, ldap.filter
 from libs.ldaplib import attrs, ldaputils
 
 cfg = web.iredconfig
     def init_passwd(self, dn, passwd):
         self.conn.passwd_s(dn, '', passwd)
 
-    def change_passwd(self, dn, cur_passwd, new_passwd, new_passwd_confirm):
-        # Username should be dn.
-        if cur_passwd == '':
-            return 'EMPTY_CUR_PW'
-        elif new_passwd == '' or new_passwd_confirm == '':
-            return 'EMPTY_NEW_PW'
-        elif new_passwd != new_passwd_confirm:
-            # Verify new password.
-            return 'NEW_PW_NOT_SAME'
-        else:
+    def change_passwd(self, dn, cur_passwd, newpw, confirmpw):
+        self.dn = ldap.filter.escape_filter_chars(dn)
+        result = iredutils.getNewPassword(newpw, confirmpw)
+        if result[0] is True:
             try:
                 # Reference: RFC3062 - LDAP Password Modify Extended Operation
-                self.conn.passwd_s(dn, cur_passwd, new_passwd)
-                return True
-            except ldap.UNWILLING_TO_PERFORM, e:
-                if web.safestr(e.args[0].get('info')) == 'unwilling to verify old password':
-                    return 'BAD_OLD_PASSWD'
-                else:
-                    return 'UNWILLING_TO_PERFORM'
+                self.conn.passwd_s(self.dn, cur_passwd, result[1])
+                return (True, 'SUCCESS')
             except ldap.LDAPError, e:
-                return str(e.args[0].get('info'))
+                return (False, str(e))
+        else:
+            return result
 
     def check_domain_exist(self, domainName):
         self.result = self.conn.search_s(

File libs/ldaplib/preferences.py

     def update(self, data):
         self.lang = web.safestr(data.get('preferredLanguage', 'en_US'))
         self.cur_passwd = data.get('cur_passwd')
-        self.new_passwd = data.get('new_passwd')
-        self.new_passwd_confirm = data.get('new_passwd_confirm')
+        self.newpw = data.get('newpw')
+        self.confirmpw = data.get('confirmpw')
 
         mod_attrs = [
                 (ldap.MOD_REPLACE, 'preferredLanguage', self.lang)
         self.dn = ldaputils.convEmailToAdminDN(session.get('username'))
         try:
             self.conn.modify_s(self.dn, mod_attrs)
+            self.change_passwd(
+                    dn=self.dn,
+                    cur_passwd=self.cur_passwd,
+                    newpw=self.newpw,
+                    confirmpw=self.confirmpw,
+                    )
             return (True, 'SUCCESS')
         except ldap.LDAPError, e:
             return (False, str(e))

File templates/default/ldap/macros.html

         <div class="sf-set {%if firstitem == 'yes' %}set1{%endif%}">
             <div class="sf-box text required">
                 <label for="oldpw"><span>{{ _('Old password') }} <em>{{ _('(Required)') }}</em></span></label><br />
-                <span class="fld-input"><input type="password" id="oldpw" name="oldpw" size="35" value="{{oldpw}}"/></span><br />
+                <span class="fld-input"><input type="password" name="oldpw" size="35" value="{{oldpw}}"/></span><br />
             </div>
         </div>
         {% endif %}
         <div class="sf-set">
             <div class="sf-box text required">
                 <label for="newpw"><span>{{ _('New password') }} <em>{{ _('(Required)') }}</em></span></label><br />
-                <span class="fld-input"><input type="password" id="newpw" name="newpw" size="35" value="{{newpw}}"/></span><br />
+                <span class="fld-input"><input type="password" name="newpw" size="35" value="{{newpw}}"/></span><br />
             </div>
         </div>
 
         <div class="sf-set">
             <div class="sf-box text required">
                 <label for="confirmpw"><span>{{ _('Confirm new password') }} <em>{{ _('(Required)') }}</em></span> <small>{{ _('Re-enter your password exactly as before.') }}</small></label><br />
-                <span class="fld-input"><input type="password" id="confirmpw" name="confirmpw" size="35" value="{{confirmpw}}"/></span><br />
+                <span class="fld-input"><input type="password" name="confirmpw" size="35" value="{{confirmpw}}"/></span><br />
             </div>
         </div>
         {% endif %}

File templates/default/ldap/preferences.html

 
             <div class="sf-box text">
                 <label><span>{{ _('New password') }}</span></label><br />
-                <span class="fld-input"><input type="password" id="new_passwd" name="new_passwd" size="25" /></span>
+                <span class="fld-input"><input type="password" name="newpw" size="25" /></span>
             </div>
 
             <div class="sf-box text">
                 <label><span>{{ _('Retype new password') }}</span></label><br />
-                <span class="fld-input"><input type="password" id="new_passwd_confirm" name="new_passwd_confirm" size="25" /></span>
+                <span class="fld-input"><input type="password" name="confirmpw" size="25" /></span>
             </div>
         </div>