def __init__(self, parent=None): QDialog.__init__(self) self.ui=Ui_Jendela() self.ui.setupUi(self) conf=QFile("ldap.xml") conf.open(QIODevice.ReadOnly) doc=QDomDocument(); doc.setContent(conf) conf.close() self.cachePass="" docElementRoot=doc.documentElement() if docElementRoot.attribute("name", "") != "kunciku": print "kunciku configuration not valid !" sys.exit(1) server=docElementRoot.firstChildElement("server") self.serv=server.attribute("value", "ldap://localhost") domain=docElementRoot.firstChildElement("domain") self.suffix=domain.attribute("value","") self.setWindowTitle("KunciKu [ %s ]" % self.suffix) unit=docElementRoot.firstChildElement("unit") unitNode=unit.firstChildElement() while not unitNode.isNull(): self.ui.cmbOu.addItem(unitNode.attribute("value", "")); unitNode=unitNode.nextSiblingElement(); self.ui.cmbOu.setCurrentIndex(-1) QObject.connect(self.ui.button, SIGNAL("clicked()"), self.clickButton)
class KunciKu(QDialog): def __init__(self, parent=None): QDialog.__init__(self) self.ui=Ui_Jendela() self.ui.setupUi(self) conf=QFile("ldap.xml") conf.open(QIODevice.ReadOnly) doc=QDomDocument(); doc.setContent(conf) conf.close() self.cachePass="" docElementRoot=doc.documentElement() if docElementRoot.attribute("name", "") != "kunciku": print "kunciku configuration not valid !" sys.exit(1) server=docElementRoot.firstChildElement("server") self.serv=server.attribute("value", "ldap://localhost") domain=docElementRoot.firstChildElement("domain") self.suffix=domain.attribute("value","") self.setWindowTitle("KunciKu [ %s ]" % self.suffix) unit=docElementRoot.firstChildElement("unit") unitNode=unit.firstChildElement() while not unitNode.isNull(): self.ui.cmbOu.addItem(unitNode.attribute("value", "")); unitNode=unitNode.nextSiblingElement(); self.ui.cmbOu.setCurrentIndex(-1) QObject.connect(self.ui.button, SIGNAL("clicked()"), self.clickButton) def checkInput(self): if self.ui.leUid.text().isEmpty(): QMessageBox.warning(self, "Warnig", "Please input uid") self.ui.leUid.setFocus() return False elif self.ui.cmbOu.currentIndex() < 0: QMessageBox.warning(self, "Warning", "Please select OrganizationalUnit") self.ui.cmbOu.setFocus() return False elif self.ui.lePwd.text().isEmpty(): QMessageBox.warning(self, "Warning", "Please input password") self.ui.lePwd.setFocus() return False return True def clickButton(self): if self.checkInput(): conn=ldap.initialize(str(self.serv)) user=str("uid=%s, ou=%s, %s" % (self.ui.leUid.text(), self.ui.cmbOu.currentText(), self.suffix) ) password=str(self.ui.lePwd.text()) if self.ui.label_3.text()=="Password": try: conn.bind_s(user, password) self.cachePass=password self.ui.leUid.setEnabled(False) self.ui.cmbOu.setEnabled(False) self.ui.label_3.setText("New Password") self.ui.lePwd.clear() self.ui.button.setText("&Change Now") self.ui.lePwd.setFocus() except ldap.LDAPError, err: QMessageBox.critical(self, "Error", err[0]['desc']) elif self.ui.label_3.text()=="New Password": try: conn.bind_s(user, self.cachePass) attrs={'userPassword' : self.cachePass} attrs_new={'userPassword' : str(self.ui.lePwd.text())} ldif=modlist.modifyModlist(attrs, attrs_new) conn.modify_s(user, ldif) conn.unbind_s() self.ui.leUid.setEnabled(True) self.ui.leUid.clear() self.ui.cmbOu.setEnabled(True) self.ui.cmbOu.clear() self.ui.label_3.setText("Password") self.ui.lePwd.clear() self.ui.button.setText("&Login") self.ui.leUid.setFocus() self.cachePass="" except ldap.LDAPError, err: QMessageBox.critical(self, "Error", err[0]['desc'])