mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
Ref T586, allow to do SSO even if the user not yet is enabled in the DB
Rational: user can do authenticated mappings/quick mapping without the account approved
This commit is contained in:
committed by
Mat Sutcliffe
parent
e2e7621e48
commit
f9884cd585
@@ -11,7 +11,6 @@
|
||||
#include "blackcore/db/databaseauthentication.h"
|
||||
#include "blackmisc/json.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/network/authenticateduser.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
@@ -36,6 +35,12 @@ namespace BlackCore
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
const CLogCategoryList &CDatabaseAuthenticationService::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats { CLogCategory::swiftDbWebservice() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
CDatabaseAuthenticationService::CDatabaseAuthenticationService(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
@@ -63,9 +68,9 @@ namespace BlackCore
|
||||
CStatusMessageList CDatabaseAuthenticationService::login(const QString &username, const QString &password)
|
||||
{
|
||||
CStatusMessageList msgs;
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
static const CLogCategoryList cats(getLogCategories().join({ CLogCategory::validation() }));
|
||||
|
||||
if (m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; }
|
||||
if (!sApp || m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; }
|
||||
|
||||
const QString un(username.trimmed());
|
||||
const QString pw(password.trimmed());
|
||||
@@ -96,6 +101,7 @@ namespace BlackCore
|
||||
|
||||
void CDatabaseAuthenticationService::logoff()
|
||||
{
|
||||
if (!sApp) { return; }
|
||||
CUrl url(sApp->getGlobalSetup().getDbLoginServiceUrl());
|
||||
url.setQuery("logoff=true");
|
||||
QNetworkRequest request(CNetworkUtils::getSwiftNetworkRequest(url));
|
||||
@@ -133,7 +139,7 @@ namespace BlackCore
|
||||
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
const QJsonObject jsonObj(Json::jsonObjectFromString(json));
|
||||
const CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj);
|
||||
CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj);
|
||||
CStatusMessageList msgs;
|
||||
if (jsonObj.contains("messages"))
|
||||
{
|
||||
@@ -141,6 +147,16 @@ namespace BlackCore
|
||||
msgs.setCategories(cats);
|
||||
}
|
||||
|
||||
// allow auto enabled for SSO users
|
||||
if (user.isValid() && !user.isEnabled())
|
||||
{
|
||||
if (user.getRoles().hasRole("VATSIMUSER"))
|
||||
{
|
||||
user.setEnabled(true);
|
||||
msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityInfo, u"Auto enabled SSO user"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!user.isAuthenticated() || !user.isValid())
|
||||
{
|
||||
if (!msgs.hasErrorMessages())
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#ifndef BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H
|
||||
#define BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/data/authenticateduser.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
|
||||
#include <QObject>
|
||||
@@ -32,6 +33,9 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Log categories
|
||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Constructor
|
||||
CDatabaseAuthenticationService(QObject *parent = nullptr);
|
||||
|
||||
@@ -64,7 +68,7 @@ namespace BlackCore
|
||||
//! User object changed
|
||||
void userChanged();
|
||||
|
||||
BlackMisc::CData<BlackCore::Data::TAuthenticatedDbUser> m_swiftDbUser {this, &CDatabaseAuthenticationService::userChanged};
|
||||
BlackMisc::CData<BlackCore::Data::TAuthenticatedDbUser> m_swiftDbUser { this, &CDatabaseAuthenticationService::userChanged };
|
||||
bool m_shutdown = false;
|
||||
};
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user