示例#1
0
TwitterEditAccountWidget::TwitterEditAccountWidget(TwitterMicroBlog *microblog,
                                                    TwitterAccount* account, QWidget* parent)
    : ChoqokEditAccountWidget(account, parent), mAccount(account)
{
    setupUi(this);
    kcfg_basicAuth->hide();
    connect(kcfg_authorize, SIGNAL(clicked(bool)), SLOT(authorizeUser()));
    if(mAccount) {
        kcfg_alias->setText( mAccount->alias() );
        if(mAccount->oauthToken().isEmpty() || mAccount->oauthTokenSecret().isEmpty()) {
            setAuthenticated(false);
        } else {
            setAuthenticated(true);
            token = mAccount->oauthToken();
            tokenSecret = mAccount->oauthTokenSecret();
            username = mAccount->username();
        }
    } else {
        setAuthenticated(false);
        QString newAccountAlias = microblog->serviceName();
        QString servName = newAccountAlias;
        int counter = 1;
        while(Choqok::AccountManager::self()->findAccount(newAccountAlias)){
            newAccountAlias = QString("%1%2").arg(servName).arg(counter);
        counter++;
    }
        setAccount( mAccount = new TwitterAccount(microblog, newAccountAlias) );
        kcfg_alias->setText( newAccountAlias );
    }
    loadTimelinesTableState();
    kcfg_alias->setFocus(Qt::OtherFocusReason);
}
/*!
    \fn bool FacebookConnection::deauthenticate()

    Deauthenticates user with Facebook.

    Returns true if the operation was successfully started and there will be a
    deauthenticateCompleted() signal emitted later; otherwise returns false.
*/
bool FacebookConnection::deauthenticate()
{
    setAuthenticated(false);
    QMetaObject::invokeMethod(this, "deauthenticateCompleted", Qt::QueuedConnection, Q_ARG(bool, true));

    return true;
}
示例#3
0
void TwitterEditAccountWidget::getPinCode()
{
    isAuthenticated = false;
    while(!isAuthenticated){
        QString verifier = KInputDialog::getText( i18n("PIN number"),
                                                  i18n("Enter PIN number received from Twitter:"));
        if(verifier.isEmpty())
            return;
        QOAuth::ParamMap otherArgs;
        otherArgs.insert( "oauth_verifier", verifier.toUtf8() );

        // send a request to exchange Request Token for an Access Token
        QOAuth::ParamMap reply =
            qoauth->accessToken( "https://twitter.com/oauth/access_token", QOAuth::POST, token,
                                tokenSecret, QOAuth::HMAC_SHA1, otherArgs );
        // if no error occurred, read the Access Token (and other arguments, if applicable)
        if ( qoauth->error() == QOAuth::NoError ) {
            username = reply.value( "screen_name" );
            token = reply.value( QOAuth::tokenParameterName() );
            tokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
            setAuthenticated(true);
            KMessageBox::information(this, i18n("Choqok is authorized successfully."),
                                     i18n("Authorized"));
        } else {
            kDebug()<<"ERROR: "<<qoauth->error()<<' '<<Choqok::qoauthErrorText(qoauth->error());
            KMessageBox::detailedError(this, i18n("Authorization Error"),
                                    Choqok::qoauthErrorText(qoauth->error()));
        }
    }
}
示例#4
0
void FSBMOSF::authenticate(const QString &username, const QString &password)
{
	bool success = false;

	if (_dataManager && username!="")
	{
		_settings.setValue("OSFUsername", username);

		_dataManager->setAuthentication(OnlineDataManager::OSF, username, password);

		success = _dataManager->authenticationSuccessful(OnlineDataManager::OSF);

		if (success)
			_settings.setValue("OSFPassword", password);
		else
			_settings.remove("OSFPassword");

		_settings.sync();
	}


	_settings.sync();

	setAuthenticated(success);
}
示例#5
0
void FSBMOSF::setOnlineDataManager(OnlineDataManager *odm)
{
	_dataManager = odm;

	_manager = odm->getNetworkAccessManager(OnlineDataManager::OSF);

	if (_isAuthenticated == false && _dataManager != NULL && _dataManager->authenticationSuccessful(OnlineDataManager::OSF))
		setAuthenticated(true);
}
示例#6
0
ClientThread::ClientThread(SOCKET client_socket, const QString &clientAddr, QObject *parent) :
    QThread(parent)
{
    mSocket = client_socket;
    mTerminated = false;
    setAuthenticated(false);
    ftpFileSystem = NULL;
    mIsUTF8 = Settings::getInstance()->getForceUtf8();
    mPassiveDataSocket = INVALID_SOCKET;
    mRenameBeginned = false;
    mClientAddr = clientAddr;
}
示例#7
0
// Misc
void BF3Widget::onLoginHashedCommand(bool auth)
{
    if (auth) {
        // Call commands on startup.
        setAuthenticated(true);
    } else {
        int ret = QMessageBox::warning(0, tr("Error"), "Wrong password, make sure you typed in the right password and try again.");

        if (ret) {
            con->hostDisconnect();
        }
    }
}
/*!
    \fn bool FacebookConnection::authenticate()

    Authenticates user with Facebook. User is authenticated if Facebook
    \l {FacebookConnection::accessToken}{access token} is valid. User can
    also make requests to publically available Facebook data without
    authentication.

    Returns true if the operation was successfully started and there will be a
    authenticateCompleted() signal emitted later; otherwise returns false.
*/
bool FacebookConnection::authenticate()
{
    bool ret = m_facebook->isAuthorized();

    if (!busy() && !ret) {
        m_apiCall = Authenticate;

        WebInterface *webInterface = qobject_cast<WebInterface*>(SocialConnection::webInterface());

        if (webInterface) {
            webInterface->setActive(true);
            setBusy(true);
            setAccessToken("");
            setAuthenticated(false);

            QString url = QString(UrlAuthenticationFormat).arg(OAuthUrlStr)
                    .arg(clientId()).arg(SuccessUrlStr);

            // Add permissions to the authorization URL
            if (m_permissions.count() > 0) {
                url += "&scope=";
                url += m_permissions.join(",");
            }

            webInterface->setUrl(url);

            ret = true;
        }
    }
    else if (ret){
        setAuthenticated(true);
        QMetaObject::invokeMethod(this, "authenticateCompleted", Qt::QueuedConnection, Q_ARG(bool, true));
    }

    return ret;
}
示例#9
0
void FSBMOSF::attemptToConnect()
{
	QString password = _settings.value("OSFPassword", "").toString();
	QString username = _settings.value("OSFUsername", "").toString();

	if ( username=="" || password =="" )
		return;

	if ( _isAuthenticated == false && _dataManager != NULL )
	{
		emit hideAuthentication();
		emit processingEntries();
		bool authsuccess = _dataManager->authenticationSuccessful(OnlineDataManager::OSF);
		setAuthenticated(authsuccess);
		if (!authsuccess)
			emit entriesChanged();
	}
}
示例#10
0
void CloudAuthenticator::replyFinished(QNetworkReply *reply)
{
    int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

    // token request
    if (m_tokenRequests.contains(reply)) {

        QByteArray data = reply->readAll();
        m_tokenRequests.removeAll(reply);

        if (reply->error() != QNetworkReply::NoError) {
            qCWarning(dcCloud()) << "Authenticator: Request token reply error:" << status << reply->errorString();            
            m_error = Cloud::CloudErrorIdentityServerNotReachable;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        // check HTTP status code
        if (status != 200) {
            qCWarning(dcCloud()) << "Authenticator: Request token reply HTTP error:" << status << reply->errorString();
            qCWarning(dcCloud()) << data;
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        // check JSON
        QJsonParseError error;
        QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
        if (error.error != QJsonParseError::NoError) {
            qCWarning(dcCloud()) << "Authenticator: Request token reply JSON error:" << error.errorString();
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        if (!jsonDoc.toVariant().toMap().contains("access_token")) {
            qCWarning(dcCloud()) << "Authenticator: Could not get access token" << jsonDoc.toJson();
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        m_error = Cloud::CloudErrorNoError;
        setToken(jsonDoc.toVariant().toMap().value("access_token").toString());
        setAuthenticated(true);

        // Save the username
        GuhSettings settings(GuhSettings::SettingsRoleDevices);
        settings.beginGroup("Cloud");
        settings.setValue("userName", m_username);
        settings.endGroup();

        if (jsonDoc.toVariant().toMap().contains("expires_in") && jsonDoc.toVariant().toMap().contains("refresh_token")) {
            int expireTime = jsonDoc.toVariant().toMap().value("expires_in").toInt();
            setRefreshToken(jsonDoc.toVariant().toMap().value("refresh_token").toString());
            qCDebug(dcCloud()) << "Authenticator: Token will be refreshed in" << expireTime << "[s]";
            m_timer->start((expireTime - 20) * 1000);
        }

    } else if (m_refreshTokenRequests.contains(reply)) {

        QByteArray data = reply->readAll();
        m_refreshTokenRequests.removeAll(reply);

        if (reply->error() != QNetworkReply::NoError) {
            qCWarning(dcCloud()) << "Authenticator: Request token reply error:" << status << reply->errorString();
            m_error = Cloud::CloudErrorIdentityServerNotReachable;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        // check HTTP status code
        if (status != 200) {
            qCWarning(dcCloud()) << "Authenticator: Refresh token reply HTTP error:" << status << reply->errorString();
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        // check JSON
        QJsonParseError error;
        QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
        if (error.error != QJsonParseError::NoError) {
            qCWarning(dcCloud()) << "Authenticator: Refresh token reply JSON error:" << error.errorString();
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        if (!jsonDoc.toVariant().toMap().contains("access_token")) {
            qCWarning(dcCloud()) << "Authenticator: Could not get access token after refresh" << jsonDoc.toJson();
            m_error = Cloud::CloudErrorAuthenticationFailed;
            setAuthenticated(false);
            reply->deleteLater();
            return;
        }

        m_error = Cloud::CloudErrorNoError;
        setToken(jsonDoc.toVariant().toMap().value("access_token").toString());
        qCDebug(dcCloud()) << "Authenticator: Token refreshed successfully";

        if (jsonDoc.toVariant().toMap().contains("expires_in") && jsonDoc.toVariant().toMap().contains("refresh_token")) {
            int expireTime = jsonDoc.toVariant().toMap().value("expires_in").toInt();
            setRefreshToken(jsonDoc.toVariant().toMap().value("refresh_token").toString());
            qCDebug(dcCloud()) << "Authenticator: Token will be refreshed in" << expireTime << "[s]";
            m_timer->start((expireTime - 20) * 1000);
        }

        if (!authenticated())
            setAuthenticated(true);

    }

    reply->deleteLater();
}
示例#11
0
/* Connection */
void BF3Widget::onConnected()
{
    setAuthenticated(false);

//    logEvent("Connected", tr("Connected to %1:%2.").arg(con->tcpSocket->peerAddress().toString()).arg(con->tcpSocket->peerPort()));
}
示例#12
0
void FrostbiteClient::onLoginHashedCommand(bool authenticated)
{
    setAuthenticated(authenticated);
}
示例#13
0
void FrostbiteClient::onDisconnected()
{
    setAuthenticated(false);
}
示例#14
0
void ClientThread::analizeCommand(QByteArray &bytearray){
    QString userName;
    if (bytearray.contains("USER")) {
        QRegExp rx("^USER\\s(.*)");
        rx.indexIn(bytearray);
        userName = rx.cap(1);
        mUser = User::getUser(userName);
        sendString(FTPProtocol::getInstance()->getResponse(331));
        return;
    }

    if (bytearray.contains("PASS")) {
        QRegExp rx("^PASS\\s(.*)");
        rx.indexIn(bytearray);
        QString pass = rx.cap(1);
        if (mUser.isNull())
        {
            sendString(FTPProtocol::getInstance()->getResponse(503,"PASS send before USER"));
        }
        else
        {
            if (mUser.auth(pass))
            {
                // logged in
                 sendString(FTPProtocol::getInstance()->getResponse(230));
                 setAuthenticated(true);
                 if (ftpFileSystem != NULL)
                    delete ftpFileSystem;
                 ftpFileSystem = new FtpFileSystem(mUser.getFolder(), mUser.getFileAccess());
            }
            else
            {
                // incorrect
                 sendString(FTPProtocol::getInstance()->getResponse(530));
            }
        }
        return;
    }
    if (isAuthenticated())
    {
        // RNFR -> RNTO sequence
        if (mRenameBeginned){
            if (bytearray.contains("RNTO")){
                QRegExp rx("^RNTO\\s(.*)");
                rx.indexIn(fromEncoding(bytearray));
                QString newName = rx.cap(1);
                mRenameBeginned = false;
                if (ftpFileSystem->rename(mRenameOldName, newName))
                    sendString(FTPProtocol::getInstance()->getResponse(250));
                else
                    sendString(FTPProtocol::getInstance()->getResponse(550));
                return;
            }
            sendString(FTPProtocol::getInstance()->getResponse(503));
            return;
        }
        if (bytearray.contains("SYST")){
            QString syst("Windows Type : L8");
            sendString(FTPProtocol::getInstance()->getResponse(215, syst));
            return;
        }
        if (bytearray.contains("FEAT")){
            QString syst("211-Features:\n\rMDTM\n\rREST STREAM\n\rSIZE\n\rMLST type*;size*;modify*;\n\rMLSD\n\rUTF8\n\rCLNT\n\rMFMT\n\r211 End");
            sendString(syst);
            return;
        }
        if (bytearray.contains("HELP")){
            QString syst("HELP OK");
            sendString(FTPProtocol::getInstance()->getResponse(214, syst));
            return;
        }
        if (bytearray.contains("PWD")){
            sendString(FTPProtocol::getInstance()->getResponse(257, toEncoding("\""+ftpFileSystem->getWorkingDirectory()+"\"")));
            return;
        }
        if (bytearray.contains("OPTS")){
            QRegExp rx("^OPTS ([\\w\\s]+)");
            rx.indexIn(bytearray);
            QRegExp rx2("^UTF8 (\\w+)");
            rx2.indexIn(rx.cap(1));
            if (rx2.cap(1) == "ON")
            {
                mIsUTF8 = true;
            }
            if (rx2.cap(1) == "OFF")
            {
                mIsUTF8 = false;
            }
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
        }
        if (bytearray.contains("TYPE")){
            // set transfer type
            QRegExp rx("^TYPE (\\w)( (\\w))?");
            rx.indexIn(bytearray);
            qDebug() << "type" << rx.cap(1) << rx.cap(3);
            mType = rx.cap(1);
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
            if (mType == "I")
            {
                sendString(FTPProtocol::getInstance()->getResponse(200));
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("PORT")){
            mIsActiveMode = true;
            QRegExp rx("^PORT (\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)");
            rx.indexIn(bytearray);
            int p1,p2;
            QString buf(rx.cap(5));
            bool flag;
            p1 = rx.cap(5).toInt(&flag);
            p2 = rx.cap(6).toInt(&flag);
            QString addr = rx.cap(1)+"."+rx.cap(2)+"."+rx.cap(3)+"."+rx.cap(4);
            active_addr = addr;
            active_port = p1*256+p2;
            sendString(FTPProtocol::getInstance()->getResponse(200, "Port ok"));
            return;
        }

        if (bytearray.contains("LIST")){
            sendString(FTPProtocol::getInstance()->getResponse(150));
            sendList();
            sendString(FTPProtocol::getInstance()->getResponse(226));
            return;
        }
        if (bytearray.contains("QUIT")){
            sendString(FTPProtocol::getInstance()->getResponse(221));
            closeconnection();
            return;
        }
        if (bytearray.contains("CDUP")){
            if (ftpFileSystem->cdUp())
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("CWD")){
            QRegExp rx("^CWD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString subFolder = rx.cap(1);
            if (ftpFileSystem->changeDir(subFolder))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("RETR")){
            QRegExp rx("^RETR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileRead(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                sendFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("STOR")){
            QRegExp rx("^STOR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileWrite(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                recvFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("RMD")){
            QRegExp rx("^RMD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->removeDir(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("DELE")){
            QRegExp rx("^DELE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->deleteFile(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("MKD")){
            QRegExp rx("^MKD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString dirName = rx.cap(1);
            if (ftpFileSystem->mkDir(dirName))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("PASV")){
            mIsActiveMode = false;
            selectPassivePort();
            return;
        }
        if (bytearray.contains("SIZE")){
            QRegExp rx("^SIZE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            qint64 size;
            if (ftpFileSystem->getSize(fileName, &size))
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, QString::number(size)));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("MDTM")){
            QRegExp rx("^MDTM\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            QString sdate = ftpFileSystem->getLastModified(fileName);
            if (sdate != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, sdate));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("RNFR")){
            QRegExp rx("^RNFR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            mRenameOldName = rx.cap(1);

            if (ftpFileSystem->exist(mRenameOldName) && ftpFileSystem->isWritable(mRenameOldName))
            {
                sendString(FTPProtocol::getInstance()->getResponse(350));
                mRenameBeginned = true;
            }
            else
                sendString(FTPProtocol::getInstance()->getResponse(550, "Permission denied"));
            return;
        }
    sendString(FTPProtocol::getInstance()->getResponse(500));
    }
    else
        sendString(FTPProtocol::getInstance()->getResponse(530));
}