actual pasword reasking on failed authentication

This commit is contained in:
Blue 2022-04-14 11:13:27 +03:00
parent ce686e121b
commit 8f949277f6
Signed by: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 347 additions and 28 deletions

View file

@ -43,6 +43,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
reconnectTimer(new QTimer),
network(p_net),
passwordType(Shared::AccountPassword::plain),
lastError(Error::none),
pepSupport(false),
active(p_active),
notReadyPassword(false),
@ -183,6 +184,7 @@ void Core::Account::onClientStateChange(QXmppClient::State st)
dm->requestItems(getServer());
dm->requestInfo(getServer());
}
lastError = Error::none;
emit connectionStateChanged(state);
}
} else {
@ -415,6 +417,7 @@ void Core::Account::onClientError(QXmppClient::Error err)
qDebug() << "Error";
QString errorText;
QString errorType;
lastError = Error::other;
switch (err) {
case QXmppClient::SocketError:
errorText = client.socketErrorString();
@ -456,6 +459,7 @@ void Core::Account::onClientError(QXmppClient::Error err)
break;
case QXmppStanza::Error::NotAuthorized:
errorText = "Authentication error";
lastError = Error::authentication;
break;
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 3, 0)
case QXmppStanza::Error::PaymentRequired:
@ -750,3 +754,6 @@ void Core::Account::renameContactRequest(const QString& jid, const QString& newN
void Core::Account::invalidatePassword() {
notReadyPassword = true;}
Core::Account::Error Core::Account::getLastError() const {
return lastError;}

View file

@ -61,6 +61,12 @@ class Account : public QObject
friend class RosterHandler;
friend class VCardHandler;
public:
enum class Error {
authentication,
other,
none
};
Account(
const QString& p_login,
const QString& p_server,
@ -82,6 +88,7 @@ public:
QString getFullJid() const;
Shared::Availability getAvailability() const;
Shared::AccountPassword getPasswordType() const;
Error getLastError() const;
bool getActive() const;
void setName(const QString& p_name);
@ -166,6 +173,7 @@ private:
NetworkAccess* network;
Shared::AccountPassword passwordType;
Error lastError;
bool pepSupport;
bool active;
bool notReadyPassword;

View file

@ -260,7 +260,10 @@ void Core::Squawk::disconnectAccount(const QString& account)
void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state)
{
Account* acc = static_cast<Account*>(sender());
emit changeAccount(acc->getName(), {{"state", QVariant::fromValue(p_state)}});
emit changeAccount(acc->getName(), {
{"state", QVariant::fromValue(p_state)},
{"error", ""}
});
#ifdef WITH_KWALLET
if (p_state == Shared::ConnectionState::connected) {
@ -398,6 +401,7 @@ void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString,
Shared::ConnectionState st = acc->getState();
QMap<QString, QVariant>::const_iterator mItr;
bool needToReconnect = false;
bool wentReconnecting = false;
mItr = map.find("login");
if (mItr != map.end()) {
@ -428,6 +432,7 @@ void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString,
if (mItr == map.end() || mItr->toBool() == acc->getActive()) {
if (needToReconnect && st != Shared::ConnectionState::disconnected) {
acc->reconnect();
wentReconnecting = true;
}
} else {
acc->setActive(mItr->toBool());
@ -468,8 +473,12 @@ void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString,
}
#endif
if (activeChanged && acc->getActive() && state != Shared::Availability::offline) {
acc->connect();
if (state != Shared::Availability::offline) {
if (activeChanged && acc->getActive()) {
acc->connect();
} else if (!wentReconnecting && acc->getActive() && acc->getLastError() == Account::Error::authentication) {
acc->connect();
}
}
emit changeAccount(name, map);
@ -479,6 +488,10 @@ void Core::Squawk::onAccountError(const QString& text)
{
Account* acc = static_cast<Account*>(sender());
emit changeAccount(acc->getName(), {{"error", text}});
if (acc->getLastError() == Account::Error::authentication) {
emit requestPassword(acc->getName(), true);
}
}
void Core::Squawk::removeAccountRequest(const QString& name)
@ -733,7 +746,7 @@ void Core::Squawk::onAccountNeedPassword()
Account* acc = static_cast<Account*>(sender());
switch (acc->getPasswordType()) {
case Shared::AccountPassword::alwaysAsk:
emit requestPassword(acc->getName());
emit requestPassword(acc->getName(), false);
break;
case Shared::AccountPassword::kwallet: {
#ifdef WITH_KWALLET
@ -741,7 +754,7 @@ void Core::Squawk::onAccountNeedPassword()
kwallet.requestReadPassword(acc->getName());
} else {
#endif
emit requestPassword(acc->getName());
emit requestPassword(acc->getName(), false);
#ifdef WITH_KWALLET
}
#endif
@ -754,7 +767,7 @@ void Core::Squawk::onAccountNeedPassword()
void Core::Squawk::onWalletRejectPassword(const QString& login)
{
emit requestPassword(login);
emit requestPassword(login, false);
}
void Core::Squawk::responsePassword(const QString& account, const QString& password)

View file

@ -86,7 +86,7 @@ signals:
void responseVCard(const QString& jid, const Shared::VCard& card);
void changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
void requestPassword(const QString& account);
void requestPassword(const QString& account, bool authernticationError);
public slots:
void start();