File indexing completed on 2024-06-16 04:42:41

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "passwordauthenticationinterface.h"
0008 #include "ddpapi/ddpauthenticationmanager.h"
0009 #include "ddpapi/ddpclient.h"
0010 #include "rocketchataccount.h"
0011 
0012 PasswordAuthenticationInterface::PasswordAuthenticationInterface(QObject *parent)
0013     : PluginAuthenticationInterface(parent)
0014 {
0015 }
0016 
0017 PasswordAuthenticationInterface::~PasswordAuthenticationInterface() = default;
0018 
0019 void PasswordAuthenticationInterface::login()
0020 {
0021     if (!mAccount->settings()->authToken().isEmpty() && !mAccount->settings()->tokenExpired()) {
0022         mAccount->ddp()->authenticationManager()->setAuthToken(mAccount->settings()->authToken());
0023         mAccount->ddp()->authenticationManager()->login();
0024         return;
0025     }
0026 
0027     if (!mAccount->settings()->twoFactorAuthenticationCode().isEmpty()) {
0028         mAccount->ddp()->authenticationManager()->sendOTP(mAccount->settings()->twoFactorAuthenticationCode());
0029         return;
0030     }
0031 
0032     if (mAccount->settings()->password().isEmpty()) {
0033         return;
0034     }
0035 
0036     if (mAccount->ldapEnabled()) {
0037         mAccount->ddp()->authenticationManager()->loginLDAP(mAccount->settings()->userName(), mAccount->settings()->password());
0038     } else {
0039         mAccount->ddp()->authenticationManager()->login(mAccount->settings()->userName(), mAccount->settings()->password());
0040     }
0041 }
0042 
0043 #include "moc_passwordauthenticationinterface.cpp"