1. Zhang Huangbin
  2. iredadmin-ose

Commits

Zhang Huangbin  committed 20c7ab3

Remove libs/ldaplib/preference.py, merged into admin.py.

  • Participants
  • Parent commits 54095a1
  • Branches default

Comments (0)

Files changed (3)

File controllers/ldap/admin.py

View file
  • Ignore whitespace
 session = web.config.get('_session')
 
 adminLib = admin.Admin()
-prefLib = preferences.Preferences()
 
 #
 # Admin related.
     def GET(self, mail):
         i = web.input()
         self.mail = web.safestr(mail)
-        self.langs = prefLib.get_langs()
+        self.langs = adminLib.get_langs()
 
         return render.admin_profile(
                 mail=self.mail,
     def POST(self, mail):
         i = web.input()
         self.mail = web.safestr(mail)
-        result = prefLib.update(i)
-        self.langs = prefLib.get_langs()
+
+        result = adminLib.update(i)
+        self.langs = adminLib.get_langs()
 
         cur_lang = self.langs.pop('cur_lang')
         if result[0] is True:

File libs/ldaplib/admin.py

View file
  • Ignore whitespace
 import web
 from libs.ldaplib import core, attrs
 
+cfg = web.iredconfig
 session = web.config.get('_session')
 
 class Admin(core.LDAPWrap):
             lang = session.get('lang')
         return lang
 
+    # Get available languages.
+    def get_langs(self):
+        # Get available languages.
+        self.available_langs = [ web.safestr(v)
+                for v in os.listdir(cfg.get('rootdir')+'i18n')
+                if v in languages.langmaps
+                ]
+
+        # Get language maps.
+        self.langmaps = {}
+        [ self.langmaps.update({i: languages.langmaps[i]})
+                for i in self.available_langs
+                if i in languages.langmaps
+                ]
+
+        # Get current language.
+        self.cur_lang = self.conn.search_s(
+                ldaputils.convEmailToAdminDN(session.get('username')),
+                ldap.SCOPE_BASE,
+                '(&(objectClass=mailAdmin)(%s=%s))' % (attrs.USER_RDN, session.get('username')),
+                ['preferredLanguage'],
+                )
+
+        if len(self.cur_lang[0][1]) != 0:
+            self.cur_lang = self.cur_lang[0][1]['preferredLanguage'][0]
+        else:
+            self.cur_lang = session.get('lang')
+
+        return {'cur_lang': self.cur_lang, 'langmaps': self.langmaps}
+
     # List all admin accounts.
     def list(self):
         filter = attrs.DOMAINADMIN_SEARCH_FILTER
 
         return msg
 
+    # Update admin profile.
+    # data: must be a webpy storage object.
+    def update(self, profile_type, mail, data):
+        self.profile_type = web.safestr(profile_type)
+        self.mail = web.safestr(mail)
+
+        self.lang = web.safestr(data.get('preferredLanguage', 'en_US'))
+        self.cur_passwd = data.get('cur_passwd')
+        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:
+            # Modify profiles.
+            self.conn.modify_s(self.dn, mod_attrs)
+
+            # Change password.
+            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 libs/ldaplib/preferences.py

  • Ignore whitespace
-#!/usr/bin/env python
-# encoding: utf-8
-
-# Author: Zhang Huangbin <michaelbibby (at) gmail.com>
-
-import os
-import sys
-import ldap
-import web
-from web import iredconfig as cfg
-from libs import languages
-from libs.ldaplib import core, attrs, ldaputils
-
-session = web.config.get('_session')
-
-class Preferences(core.LDAPWrap):
-    def __del__(self):
-        pass
-
-    def get_langs(self):
-        # Get available languages.
-        self.available_langs = [ web.safestr(v)
-                for v in os.listdir(cfg.get('rootdir')+'i18n')
-                if v in languages.langmaps
-                ]
-
-        # Get language maps.
-        self.langmaps = {}
-        [ self.langmaps.update({i: languages.langmaps[i]})
-                for i in self.available_langs
-                if i in languages.langmaps
-                ]
-
-        # Get current language.
-        self.cur_lang = self.conn.search_s(
-                ldaputils.convEmailToAdminDN(session.get('username')),
-                ldap.SCOPE_BASE,
-                '(&(objectClass=mailAdmin)(%s=%s))' % (attrs.USER_RDN, session.get('username')),
-                ['preferredLanguage'],
-                )
-
-        if len(self.cur_lang[0][1]) != 0:
-            self.cur_lang = self.cur_lang[0][1]['preferredLanguage'][0]
-        else:
-            self.cur_lang = session.get('lang')
-
-        return {'cur_lang': self.cur_lang, 'langmaps': self.langmaps}
-
-    # Update admin profile.
-    # data: must be a webpy storage object.
-    def update(self, data):
-        self.lang = web.safestr(data.get('preferredLanguage', 'en_US'))
-        self.cur_passwd = data.get('cur_passwd')
-        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:
-            # Modify profiles.
-            self.conn.modify_s(self.dn, mod_attrs)
-
-            # Change password.
-            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))