Пример #1
0
    def login(self, url, db):
        url = QUrl(url)
        _url = str(url.scheme()) + '://' + \
            str(url.host()) + ':' + str(url.port())
        self.connection = createConnection(_url)
        user = Url.decodeFromUrl(str(url.userName()))
        password = Url.decodeFromUrl(str(url.password()))
        try:
            res = self.connection.call('/common', 'login', db, user, password)
        except socket.error as e:
            return Session.Exception
        if not res:
            self.open = False
            self.uid = False
            return Session.InvalidCredentials

        self.url = _url
        self.open = True
        self.uid = res
        self.userName = user
        self.password = password
        self.databaseName = db
        if self.cache:
            self.cache.clear()

        self.connection.databaseName = self.databaseName
        self.connection.password = self.password
        self.connection.uid = self.uid
        self.connection.authorized = True

        self.reloadContext()
        return Session.LoggedIn
Пример #2
0
 def login(self, url, db):
     url = QUrl(url)
     _url = str(url.scheme()) + '://' + str(url.host()) + ':' + str(
         url.port())
     self.connection = createConnection(_url, allow_xmlrpc2=True)
     user = Url.decodeFromUrl(unicode(url.userName()))
     password = Url.decodeFromUrl(unicode(url.password()))
     for ttry in (1, 2):
         res = False
         try:
             res = self.connection.login(db, user, password)
             if res:
                 self._log.info('Logged into %s as %s', db, user)
             break
         except socket.error, e:
             return Session.Exception
         except tiny_socket.ProtocolError, e:
             if e.errcode == 404 and isinstance(self.connection,
                                                XmlRpc2Connection):
                 self.connection = createConnection(_url,
                                                    allow_xmlrpc2=False)
                 self._log.info(
                     "Server must be older, retrying with XML-RPC v.1")
                 continue
             self._log.error('Protocol error: %s', e)
             return Session.InvalidCredentials
Пример #3
0
    def slotAccept(self):
        m = QUrl(self.uiServer.text())
        m.setUserName(Url.encodeForUrl(self.uiUserName.text()))
        m.setPassword(Url.encodeForUrl(self.uiPassword.text()))
        if m.isValid():
            self.url = unicode(m.toString())
            if self.uiDatabase.isVisible():
                self.databaseName = unicode(self.uiDatabase.currentText())
            else:
                self.databaseName = unicode(self.uiTextDatabase.text())
            m.setPassword('')
            Settings.setValue('login.url', unicode(m.toString()))
            Settings.setValue('login.db', self.databaseName)
            Settings.saveToFile()
            self.accept()

            if Common.isKdeAvailable:
                storeWallet = Settings.value('kde.wallet', 'ask')
                if storeWallet == 'ask':
                    answer = QMessageBox.question(
                        self, _('Wallet'),
                        _('Do you want to store your password in your wallet?'
                          ), QMessageBox.Yes | QMessageBox.No
                        | QMessageBox.YesToAll | QMessageBox.NoToAll)
                    if answer == QMessageBox.YesToAll:
                        Settings.setValue('kde.wallet', 'yes')
                        Settings.saveToFile()
                        storeWallet = True
                    elif answer == QMessageBox.NoToAll:
                        Settings.setValue('kde.wallet', 'no')
                        Settings.saveToFile()
                        storeWallet = False
                    elif answer == QMessageBox.Yes:
                        storeWallet = True
                    else:
                        storeWallet = False

                if storeWallet:
                    from PyKDE4.kdeui import KWallet
                    KWallet.Wallet.NetworkWallet()
                    wallet = KWallet.Wallet.openWallet(
                        KWallet.Wallet.NetworkWallet(), self.winId())
                    if wallet:
                        folder = '%s/%s' % (unicode(
                            self.uiServer.text()), self.databaseName)
                        logging.getLogger('koo.login').debug(
                            "Storing credentials in KWallet")
                        wallet.writeMap(
                            folder, {
                                'username': unicode(self.uiUserName.text()),
                                'password': unicode(self.uiPassword.text()),
                            })
                    else:
                        logging.getLogger('koo.login').info(
                            "Wallet not opened, not storing credentials")
        else:
            self.reject()
Пример #4
0
    def login(self, url, db):
        """
        Logs in the given server with specified name and password.

        :param url: Admited protocols are 'http', 'https' and 'socket'
        url string such as 'http://*****:*****@localhost:8069'.
        :type url: str
        :param db: string with the database name
        :type db: str
        :return:
        :raises: Session.Exception, Session.InvalidCredentials or Session.LoggedIn
        """
        url = QUrl(url)
        _url = str(url.scheme()) + '://' + \
            str(url.host()) + ':' + str(url.port())
        self.connection = createConnection(_url)
        user = Url.decodeFromUrl(str(url.userName()))
        password = Url.decodeFromUrl(str(url.password()))
        try:
            res = self.connection.call('/common', 'login', db, user, password)
        except socket.error as e:
            return Session.Exception
        if not res:
            self.open = False
            self.uid = False
            return Session.InvalidCredentials

        self.url = _url
        self.open = True
        self.uid = res
        self.userName = user
        self.password = password
        self.databaseName = db
        if self.cache:
            self.cache.clear()

        self.connection.databaseName = self.databaseName
        self.connection.password = self.password
        self.connection.uid = self.uid
        self.connection.authorized = True

        self.reloadContext()
        return Session.LoggedIn