Ref T219, added some utility functions in value classes

This commit is contained in:
Klaus Basan
2018-01-07 03:09:54 +01:00
parent b982b7aca6
commit 93d1dcfc1d
7 changed files with 29 additions and 7 deletions

View File

@@ -106,7 +106,7 @@ namespace BlackMisc
bool CServer::isValidForLogin() const
{
return m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
return m_user.hasCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
}
bool CServer::hasAddressAndPort() const

View File

@@ -119,13 +119,18 @@ namespace BlackMisc
m_realname = beautifyRealName(rn);
}
bool CUser::hasValidHomeBase() const
{
return m_homebase.hasValidIcaoCode();
}
CStatusMessageList CUser::validate() const
{
CStatusMessageList msgs;
// callsign optional
if (!this->hasId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
if (!this->hasRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
if (!this->hasCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
return msgs;
}

View File

@@ -73,10 +73,13 @@ namespace BlackMisc
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
//! Valid user object?
bool isValid() const { return !m_realname.isEmpty() && !m_id.isEmpty(); }
bool isValid() const { return !isNull(); }
//! Null?
bool isNull() const { return m_realname.isEmpty() && m_id.isEmpty(); }
//! Valid credentials?
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
bool hasCredentials() const { return this->isValid() && !m_password.isEmpty(); }
//! Valid real name?
bool hasRealName() const { return !m_realname.isEmpty(); }
@@ -84,12 +87,18 @@ namespace BlackMisc
//! Valid id?
bool hasId() const { return !m_id.isEmpty(); }
//! Has a valid VATSIM id?
bool hasValidVatsimId() const { return CUser::isValidVatsimId(this->getId()); }
//! Has associated callsign?
bool hasCallsign() const { return !m_callsign.isEmpty(); }
//! Has home base?
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Has valid home base?
bool hasValidHomeBase() const;
//! Real name + homebase
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;