Changeset View
Changeset View
Standalone View
Standalone View
src/ruqolacore/ddpapi/ddpclient.cpp
Show First 20 Lines • Show All 659 Lines • ▼ Show 20 Line(s) | |||||
660 | quint64 DDPClient::loginProvider(const QString &credentialToken, const QString &credentialSecret) | 660 | quint64 DDPClient::loginProvider(const QString &credentialToken, const QString &credentialSecret) | ||
661 | { | 661 | { | ||
662 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->loginProvider(credentialToken, credentialSecret, m_uid); | 662 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->loginProvider(credentialToken, credentialSecret, m_uid); | ||
663 | return method(result, empty_callback, DDPClient::Ephemeral); | 663 | return method(result, empty_callback, DDPClient::Ephemeral); | ||
664 | } | 664 | } | ||
665 | 665 | | |||
666 | quint64 DDPClient::login(const QString &username, const QString &password) | 666 | quint64 DDPClient::login(const QString &username, const QString &password) | ||
667 | { | 667 | { | ||
668 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->login(username, password, m_uid); | 668 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->login(username, password, mRocketChatAccount->settings()->twoFactorAuthenticationCode(), m_uid); | ||
669 | return method(result, login_result, DDPClient::Ephemeral); | 669 | return method(result, login_result, DDPClient::Ephemeral); | ||
670 | } | 670 | } | ||
671 | 671 | | |||
672 | quint64 DDPClient::addUserToRoom(const QString &username, const QString &roomId) | 672 | quint64 DDPClient::addUserToRoom(const QString &username, const QString &roomId) | ||
673 | { | 673 | { | ||
674 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->addUserToRoom(username, roomId, m_uid); | 674 | const RocketChatMessage::RocketChatMessageResult result = mRocketChatMessage->addUserToRoom(username, roomId, m_uid); | ||
675 | return method(result, add_user_to_room, DDPClient::Persistent); | 675 | return method(result, add_user_to_room, DDPClient::Persistent); | ||
676 | } | 676 | } | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 814 | } else if (messageType == QLatin1String("result")) { | |||
817 | if (m_callbackHash.contains(id)) { | 817 | if (m_callbackHash.contains(id)) { | ||
818 | std::function<void(QJsonObject, RocketChatAccount *)> callback = m_callbackHash.take(id); | 818 | std::function<void(QJsonObject, RocketChatAccount *)> callback = m_callbackHash.take(id); | ||
819 | 819 | | |||
820 | callback(root, mRocketChatAccount); | 820 | callback(root, mRocketChatAccount); | ||
821 | } | 821 | } | ||
822 | Q_EMIT result(id, QJsonDocument(root.value(QLatin1String("result")).toObject())); | 822 | Q_EMIT result(id, QJsonDocument(root.value(QLatin1String("result")).toObject())); | ||
823 | 823 | | |||
824 | if (id == m_loginJob) { | 824 | if (id == m_loginJob) { | ||
825 | if (root.value(QLatin1String("error")).toObject().value(QLatin1String("error")).toInt() == 403) { | 825 | const QJsonObject error(root.value(QLatin1String("error")).toObject()); | ||
826 | const QJsonValue errorValue(error.value(QLatin1String("error"))); | ||||
827 | if (errorValue.toInt() == 403) { | ||||
826 | qCDebug(RUQOLA_DDPAPI_LOG) << "Wrong password or token expired"; | 828 | qCDebug(RUQOLA_DDPAPI_LOG) << "Wrong password or token expired"; | ||
827 | 829 | | |||
828 | login(); // Let's keep trying to log in | 830 | login(); // Let's keep trying to log in | ||
mlaurent: const | |||||
831 | } else if (errorValue.toString() == QLatin1String("totp-required") || errorValue.toString() == QLatin1String("totp-invalid")) { | ||||
mlaurent: const | |||||
832 | qCDebug(RUQOLA_DDPAPI_LOG) << "A 2FA code or backup code is required to login"; | ||||
833 | setLoginStatus(LoginCodeRequired); | ||||
834 | } else if (!error.isEmpty()) { | ||||
835 | qCDebug(RUQOLA_DDPAPI_LOG) << error.value(QLatin1String("message")).toString(); | ||||
836 | setLoginStatus(LoginFailed); | ||||
829 | } else { | 837 | } else { | ||
830 | const QString token = root.value(QLatin1String("result")).toObject().value(QLatin1String("token")).toString(); | 838 | const QString token = root.value(QLatin1String("result")).toObject().value(QLatin1String("token")).toString(); | ||
831 | mRocketChatAccount->settings()->setAuthToken(token); | 839 | mRocketChatAccount->settings()->setAuthToken(token); | ||
832 | mRocketChatAccount->restApi()->setAuthToken(token); | 840 | mRocketChatAccount->restApi()->setAuthToken(token); | ||
mlaurent: We don't failed when we have an error ? | |||||
cdywan: Nice catch! We definitely should fail here! | |||||
833 | mRocketChatAccount->restApi()->setUserId(root.value(QLatin1String("id")).toString()); | 841 | mRocketChatAccount->restApi()->setUserId(root.value(QLatin1String("id")).toString()); | ||
834 | setLoginStatus(DDPClient::LoggedIn); | 842 | setLoginStatus(DDPClient::LoggedIn); | ||
835 | } | 843 | } | ||
836 | } | 844 | } | ||
837 | } else if (messageType == QLatin1String("connected")) { | 845 | } else if (messageType == QLatin1String("connected")) { | ||
838 | //qCDebug(RUQOLA_DDPAPI_LOG) << "Connected"; | 846 | //qCDebug(RUQOLA_DDPAPI_LOG) << "Connected"; | ||
839 | qDebug() << "Connected"; | 847 | qDebug() << "Connected"; | ||
840 | m_connected = true; | 848 | m_connected = true; | ||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |
const