| 78 | } |
| 79 | |
| 80 | void CPasswordStore::saveCredentials( |
| 81 | const QString &host, const QString &username, const QString &password) |
| 82 | { |
| 83 | if (host.isEmpty() || username.isEmpty()) return; |
| 84 | |
| 85 | const QString key = ServiceName() + QStringLiteral("autofill/%1").arg(host); |
| 86 | |
| 87 | QJsonObject obj; |
| 88 | obj.insert(QStringLiteral("username"), username); |
| 89 | obj.insert(QStringLiteral("password"), password); |
| 90 | const QString payload = |
| 91 | QString::fromUtf8(QJsonDocument(obj).toJson(QJsonDocument::Compact)); |
| 92 | auto pJob = new QKeychain::WritePasswordJob(ServiceName()); |
| 93 | bool check = connect(pJob, &QKeychain::WritePasswordJob::finished, |
| 94 | [this, host, pJob]() { |
| 95 | if (pJob->error() != QKeychain::NoError) { |
| 96 | qDebug(log) << "Saved credentials error for" << host << ":" |
| 97 | << pJob->errorString(); |
| 98 | return; |
| 99 | } |
| 100 | emit this->credentialsSaved(host); |
| 101 | qDebug(log) << "Saved credentials for" << host; |
| 102 | }); |
| 103 | Q_ASSERT(check); |
| 104 | pJob->setKey(key); |
| 105 | pJob->setTextData(payload); |
| 106 | pJob->start(); |
| 107 | } |
| 108 | #else |
| 109 | QVariantMap CPasswordStore::getCredentials(const QString &host) |
| 110 | { |
no test coverage detected