RedditModel::RedditModel(const QStringList& reddits, Application* app, QObject* parent) : QAbstractItemModel(parent), app_(app), reddits_(reddits), no_image_(QPixmap::fromImage(ScaleAndPad(QImage(":/noimage.png")))), network_(new NetworkAccessManager(this)), is_fetching_more_(false), no_more_links_(false), show_self_posts_(false), show_viewed_images_(false), preload_next_(kDefaultPreloadNext), max_preloaded_pages_(kDefaultMaxPreloadedPages) { // Read the user's cookie QSettings s; s.beginGroup(kSettingsGroup); const QString cookie = s.value("cookie").toString(); if (cookie.isEmpty()) { // Not-logged in users are only allowed to get one subreddit. while (reddits_.size() > 1) { reddits_.removeLast(); } } else { network_->cookieJar()->setCookiesFromUrl( QList<QNetworkCookie>() << QNetworkCookie(kCookieName, cookie.toAscii()), QUrl(kUrlForCookies)); } connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings())); ReloadSettings(); }
ShibbolethWebView::ShibbolethWebView(Account* account, QWidget* parent) : QWebView(parent) , _account(account) , _accepted(false) , _cursorOverriden(false) { // no minimize setWindowFlags(Qt::Dialog); setAttribute(Qt::WA_DeleteOnClose); QWebPage* page = new QWebPage(this); page->setNetworkAccessManager(account->networkAccessManager()); connect(page, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(page, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool))); connect(page->networkAccessManager()->cookieJar(), SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)), this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl))); page->mainFrame()->load(account->url()); this->setPage(page); setWindowTitle(tr("%1 - Authenticate").arg(Theme::instance()->appNameGUI())); // If we have a valid cookie, it's most likely expired. We can use this as // as a criteria to tell the user why the browser window pops up QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account, ShibbolethCredentials::accountCookies(_account)); if (shibCookie != QNetworkCookie()) { Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("Your session has expired. You need to re-login to continue to use the client.")); } }
void CookieJar::setAllCookies(const QVariantList &cookies) { #ifdef CUTETUBE_DEBUG qDebug() << "CookieJar::setAllCookies" << cookies; #endif QList<QNetworkCookie> list; foreach (QVariant v, cookies) { QVariantMap cookie = v.toMap(); list << QNetworkCookie(cookie.value("name").toString().toUtf8(), cookie.value("value").toString().toUtf8()); }
QNetworkCookie CookieJar::getCookie(const QString& name, const QUrl& url) { purgeExpiredCookies(); QList<QNetworkCookie> cookieList = cookies(url); for(int i = cookieList.count() - 1;i >= 0; --i) { if(cookieList.at(i).name() == name) return cookieList.at(i); } return QNetworkCookie(); }
void ShibbolethWebView::onNewCookiesForUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url) { if (url.host() == _account->url().host()) { QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account.data(), cookieList); if (shibCookie != QNetworkCookie()) { Q_EMIT shibbolethCookieReceived(shibCookie); accept(); close(); } } }
void CMainWindow::on_pushButton_3_clicked() { QNetworkCookieJar *m_pCookieJar = new QNetworkCookieJar(); m_pWebView->page()->networkAccessManager()->setCookieJar(m_pCookieJar); QList<QNetworkCookie> cookies; cookies.append(QNetworkCookie("key1", ui->lineEdit_2->text().toLocal8Bit())); //更多cookie按照上面的方法依次添加... m_pCookieJar->setCookiesFromUrl(cookies, ui->lineEdit->text()); // m_pCookieJar->setCookiesFromUrl(cookies, strUrl); m_pWebView->load(ui->lineEdit->text()); }
QList<QNetworkCookie> CookieJar::cookiesForUrl(const QUrl & url) const { QSettings settings(m_cookiesFile, QSettings::IniFormat); QList<QNetworkCookie> cookieList; settings.beginGroup(url.host()); QStringList keys = settings.childKeys(); for (QStringList::iterator i = keys.begin(); i != keys.end(); i++) { cookieList.push_back(QNetworkCookie((*i).toLocal8Bit(), settings.value(*i).toByteArray())); } return cookieList; }
void OwncloudShibbolethCredsPage::slotOtherCookiesReceived(const QList<QNetworkCookie>& cookieList, const QUrl& url) { QList<QNetworkCookie>& cookies(_cookiesForUrl[url]); QMap<QByteArray, QByteArray> uniqueCookies; Q_FOREACH (const QNetworkCookie& c, cookieList) { if (!c.isSessionCookie()) { cookies << c; } } Q_FOREACH (const QNetworkCookie& c, cookies) { uniqueCookies[c.name()] = c.value(); } cookies.clear(); Q_FOREACH (const QByteArray& name, uniqueCookies.keys()) { cookies << QNetworkCookie(name, uniqueCookies[name]); } }
QWidget *CGI_SCADA_DLL_TreeItemAboutMessage::GetWidget(QTreeWidgetItem *) { // if (m_pWidget == NULL) // { // m_pWidget = new UI_AboutMessage(NULL); // } // return m_pWidget; if (!m_bIP_CookieIsInit) { QList<QNetworkCookie> cookies; cookies.append(QNetworkCookie("CMMSUSS", CGI_SCADA_define::s_baCookie)); qDebug()<<__func__<<__LINE__<<CGI_SCADA_define::s_strIPAddress<<CGI_SCADA_define::s_baCookie; m_pCookieJar->setCookiesFromUrl(cookies, QString(URL_TreeItemType_About_M).arg(CGI_SCADA_define::s_strIPAddress)); m_bIP_CookieIsInit = true; } m_pMainView->load(QUrl(QString(URL_TreeItemType_About_M).arg(CGI_SCADA_define::s_strIPAddress))); return m_pMainView; }
bool CookieJar::loadCookiesFromDisk(){ std::ifstream input("cookies.dat"); if(input){ QList<QNetworkCookie> cookies; std::string cookieData; std::cout << "\nLOADING COOKIES" << std::endl << std::endl; while(getline(input, cookieData, this->COOKIE_DELIMITER)){ std::cout << cookieData << std::endl; int seperatorIndex = -1; for(int i=0; i<cookieData.length(); i++) if(cookieData[i] == '='){ seperatorIndex = i; break; } //TODO: if seperatorIndex = -1 cookie is malformed QByteArray name(cookieData.c_str(), seperatorIndex); seperatorIndex++; QByteArray data(cookieData.c_str()+seperatorIndex, cookieData.length() - seperatorIndex); qDebug() << "NAME => " << name; qDebug() << "DATA => " << data; cookies.append(QNetworkCookie(name, data)); } this->setAllCookies(cookies); return true; } else{ return false; } }
ShibbolethWebView::ShibbolethWebView(AccountPtr account, QWidget* parent) : QWebView(parent) , _account(account) , _accepted(false) , _cursorOverriden(false) { // no minimize setWindowFlags(Qt::Dialog); setAttribute(Qt::WA_DeleteOnClose); QWebPage* page = new QWebPage(this); connect(page, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(page, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool))); // Make sure to accept the same SSL certificate issues as the regular QNAM we use for syncing QObject::connect(page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), _account.data(), SLOT(slotHandleSslErrors(QNetworkReply*,QList<QSslError>))); // The Account keeps ownership of the cookie jar, it must outlive this webview. account->lendCookieJarTo(page->networkAccessManager()); connect(page->networkAccessManager()->cookieJar(), SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)), this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl))); page->mainFrame()->load(account->url()); this->setPage(page); setWindowTitle(tr("%1 - Authenticate").arg(Theme::instance()->appNameGUI())); // If we have a valid cookie, it's most likely expired. We can use this as // as a criteria to tell the user why the browser window pops up QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account.data(), ShibbolethCredentials::accountCookies(_account.data())); if (shibCookie != QNetworkCookie()) { Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("Your session has expired. You need to re-login to continue to use the client.")); } ConfigFile config; QSettings settings(config.configFile()); resize(900, 700); // only effective the first time, later overridden by restoreGeometry restoreGeometry(settings.value(ShibbolethWebViewGeometryC).toByteArray()); }
void OwncloudShibbolethCredsPage::initializePage() { _afterInitialSetup = true; _cookie = QNetworkCookie(); _cookiesForUrl.clear(); }
int p = value.length(); int p1 = value.indexOf(';'); int p2 = value.indexOf(' '); if (p1 > 0) p = p1; if (p2 > 0 && p2 < p) p = p2; QString trimmed = value.left(p); if (value.startsWith("PHPSESSID=")) phpsessid = trimmed; if (value.startsWith("num_searches_cookie=")) num_searches = trimmed; if (value.startsWith("recent_searches_cookie_1=")) recent_searches = trimmed; }*/ QList<QNetworkCookie> cookies; cookies.append(QNetworkCookie(QByteArray("partners_cookie"), partners.toAscii())); QVariant var; var.setValue(cookies); req.setHeader(QNetworkRequest::KnownHeaders::CookieHeader, var); int rpos = url.lastIndexOf('/'); if (rpos) int lpos = rpos-1; while (lpos>0 && url[lpos] != '/') lpos--; if (/bwFdr9VaFJw/
TBNetworkCookieJar::TBNetworkCookieJar(QObject *parent) : QNetworkCookieJar(parent) { keepAliveCookie = QNetworkCookie("ka", "open"); load(); }
void connectWindowClass::addCookiesManually(QString newHelloCookie, QString newConnectCookie) { cookieList.clear(); cookieList.append(QNetworkCookie("dlrowolleh", newHelloCookie.toStdString().c_str())); cookieList.append(QNetworkCookie("coniunctio", newConnectCookie.toStdString().c_str())); }