mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-11 00:49:42 +00:00
simle fixes
This commit is contained in:
parent
63919c7554
commit
5877473c2a
Heart
AbstractSpace
DataBaseSpace
@ -497,7 +497,7 @@ bool AbstractNode::sendData(const AbstractData *resp,
|
||||
}
|
||||
|
||||
void AbstractNode::badRequest(const HostAddress &address, const Header &req,
|
||||
const QString msg) {
|
||||
const QString msg, quint8 diff) {
|
||||
auto client = getInfoPtr(address);
|
||||
|
||||
if (!client) {
|
||||
@ -508,7 +508,7 @@ void AbstractNode::badRequest(const HostAddress &address, const Header &req,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changeTrust(address, REQUEST_ERROR)) {
|
||||
if (!changeTrust(address, diff)) {
|
||||
|
||||
QuasarAppUtils::Params::log("Bad request detected, bud responce command not sendet!"
|
||||
" because trust not changed",
|
||||
|
@ -342,9 +342,11 @@ protected:
|
||||
* @param address This is addrees of receiver
|
||||
* @param req This is header of incomming request
|
||||
* @param msg This is message of error
|
||||
* @param diff This is difference of current trust (currenTrus += diff)
|
||||
* By default diff equals REQUEST_ERROR
|
||||
*/
|
||||
virtual void badRequest(const HostAddress &address, const Header &req,
|
||||
const QString msg = "");
|
||||
const QString msg = "", quint8 diff = REQUEST_ERROR);
|
||||
|
||||
/**
|
||||
* @brief getWorkStateString This method generate string about work state of server.
|
||||
|
@ -196,13 +196,15 @@ bool DataBaseNode::sendData(const AbstractData *resp, const BaseId &nodeId, cons
|
||||
return false;
|
||||
}
|
||||
|
||||
void DataBaseNode::badRequest(const HostAddress &address, const Header &req, const QString msg) {
|
||||
AbstractNode::badRequest(address, req, msg);
|
||||
void DataBaseNode::badRequest(const HostAddress &address, const Header &req,
|
||||
const QString msg, quint8 diff) {
|
||||
AbstractNode::badRequest(address, req, msg, diff);
|
||||
}
|
||||
|
||||
void DataBaseNode::badRequest(const BaseId &address, const Header &req, const QString msg) {
|
||||
void DataBaseNode::badRequest(const BaseId &address, const Header &req,
|
||||
const QString msg, quint8 diff) {
|
||||
|
||||
if (!changeTrust(address, REQUEST_ERROR)) {
|
||||
if (!changeTrust(address, diff)) {
|
||||
|
||||
QuasarAppUtils::Params::log("Bad request detected, bud responce command not sendet!"
|
||||
" because trust not changed",
|
||||
|
@ -133,7 +133,7 @@ protected:
|
||||
AbstractNodeInfo *createNodeInfo(QAbstractSocket *socket, const HostAddress *clientAddress) const override;
|
||||
|
||||
void badRequest(const HostAddress &address, const Header &req,
|
||||
const QString msg = "") override;
|
||||
const QString msg = "", quint8 diff = REQUEST_ERROR) override;
|
||||
|
||||
/**
|
||||
* @brief badRequest This implementation of the AbstractNode::badRequest method
|
||||
@ -141,9 +141,11 @@ protected:
|
||||
* @param address This is id of target node or client
|
||||
* @param req This is header of request.
|
||||
* @param msg This is message for target node about error.
|
||||
* @param diff This is difference of current trust (currenTrus += diff)
|
||||
* By default diff equals REQUEST_ERROR
|
||||
*/
|
||||
virtual void badRequest(const BaseId &address, const Header &req,
|
||||
const QString msg = "");
|
||||
const QString msg = "", quint8 diff = REQUEST_ERROR);
|
||||
|
||||
bool changeTrust(const HostAddress &id, int diff) override;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "user.h"
|
||||
|
||||
#include <QDataStream>
|
||||
namespace QH {
|
||||
namespace PKG {
|
||||
|
||||
@ -25,6 +27,7 @@ bool User::copyFrom(const AbstractData *other) {
|
||||
return false;
|
||||
|
||||
this->_token = otherObject->_token;
|
||||
this->_type = otherObject->_type;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -54,6 +57,7 @@ BaseId User::generateId() const {
|
||||
QDataStream &User::fromStream(QDataStream &stream) {
|
||||
NetworkMember::fromStream(stream);
|
||||
stream >> _token;
|
||||
stream >> _type;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -61,6 +65,7 @@ QDataStream &User::fromStream(QDataStream &stream) {
|
||||
QDataStream &User::toStream(QDataStream &stream) const {
|
||||
NetworkMember::toStream(stream);
|
||||
stream << _token;
|
||||
stream << _type;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -72,6 +77,14 @@ DBVariantMap User::variantMap() const {
|
||||
return map;
|
||||
}
|
||||
|
||||
UserRequestType User::type() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
void User::setType(const UserRequestType &type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
AccessToken User::token() const {
|
||||
return _token;
|
||||
}
|
||||
|
@ -9,6 +9,18 @@ namespace QH {
|
||||
|
||||
namespace PKG {
|
||||
|
||||
/**
|
||||
* @brief The UserRequestType enum is types of request.
|
||||
*/
|
||||
enum class UserRequestType: unsigned int {
|
||||
/// This is default type. Response of server or client.
|
||||
Responce,
|
||||
/// Request to registration a new user.
|
||||
SignIn,
|
||||
/// Request to login an exists user.
|
||||
Login
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The User class is some as a NetworkMember class.
|
||||
* All registered users on the singelServer have own list database object with own permisions.
|
||||
@ -41,6 +53,19 @@ public:
|
||||
*/
|
||||
void setToken(const AccessToken &token);
|
||||
|
||||
/**
|
||||
* @brief type This method return type of request. for more information see the UserRequestType enum class.
|
||||
* @return type of request.
|
||||
*/
|
||||
UserRequestType type() const;
|
||||
|
||||
/**
|
||||
* @brief setType This method set new value for request type.
|
||||
* For more information see the UserRequestType enum class.
|
||||
* @param type This is new value of type.
|
||||
*/
|
||||
void setType(const UserRequestType &type);
|
||||
|
||||
protected:
|
||||
BaseId generateId() const override;
|
||||
QDataStream &fromStream(QDataStream &stream) override;
|
||||
@ -49,6 +74,7 @@ protected:
|
||||
|
||||
private:
|
||||
AccessToken _token;
|
||||
UserRequestType _type = UserRequestType::Responce;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,91 @@ AccessToken SingleServer::generateToken(int length) {
|
||||
return AccessToken(length);
|
||||
}
|
||||
|
||||
ParserResult SingleServer::parsePackage(const Package &pkg, const AbstractNodeInfo *sender) {
|
||||
auto parentResult = DataBaseNode::parsePackage(pkg, sender);
|
||||
if (parentResult != QH::ParserResult::NotProcessed) {
|
||||
return parentResult;
|
||||
}
|
||||
|
||||
|
||||
if (H_16<QH::PKG::User>() == pkg.hdr.command) {
|
||||
QH::PKG::User obj(pkg);
|
||||
|
||||
if (!obj.isValid()) {
|
||||
badRequest(sender->networkAddress(), pkg.hdr);
|
||||
return ParserResult::Error;
|
||||
}
|
||||
|
||||
if (!workWithUserRequest(obj, pkg, sender)) {
|
||||
return QH::ParserResult::Error;
|
||||
}
|
||||
|
||||
return QH::ParserResult::Processed;
|
||||
|
||||
}
|
||||
|
||||
return QH::ParserResult::NotProcessed;
|
||||
|
||||
}
|
||||
|
||||
bool SingleServer::workWithUserRequest(const PKG::User& obj,
|
||||
const Package &pkg,
|
||||
const AbstractNodeInfo *sender) {
|
||||
RegisteruserResult result = RegisteruserResult::InternalError;
|
||||
|
||||
if (obj.type() == PKG::UserRequestType::Login) {
|
||||
result = loginUser(obj, sender);
|
||||
} else if (obj.type() == PKG::UserRequestType::SignIn) {
|
||||
result = registerNewUser(obj, sender);
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
|
||||
case RegisteruserResult::InternalError: {
|
||||
QuasarAppUtils::Params::log("Internal error ocured in the loginUser or registerNewUser method.",
|
||||
QuasarAppUtils::Error);
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "Internal server error."
|
||||
" Please create issue about this problem in the support page "
|
||||
" https://github.com/QuasarApp/Heart/issues/new",
|
||||
REQUEST_INTERNAL_ERROR);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
case RegisteruserResult::UserExits: {
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "Such user already exists ", REQUEST_LOGIN_ERROR);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
case RegisteruserResult::UserNotExits: {
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "Such user not exists ", REQUEST_LOGIN_ERROR);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
case RegisteruserResult::UserInvalidPasswoed: {
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "Invalid password ", REQUEST_LOGIN_ERROR);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
case RegisteruserResult::UserAlreadyLogged: {
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "User Already Logged", REQUEST_LOGIN_ERROR);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
case RegisteruserResult::Success: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
badRequest(sender->networkAddress(), pkg.hdr, "Internal server error. RegisteruserResult return invalid value!"
|
||||
" Please create issue about this problem in the support page "
|
||||
" https://github.com/QuasarApp/Heart/issues/new",
|
||||
REQUEST_INTERNAL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ namespace PKG {
|
||||
class User;
|
||||
}
|
||||
|
||||
#define REQUEST_INTERNAL_ERROR 0
|
||||
#define REQUEST_LOGIN_ERROR -1
|
||||
|
||||
/**
|
||||
* @brief The RegisteruserResult enum
|
||||
*/
|
||||
@ -31,16 +34,16 @@ enum class RegisteruserResult {
|
||||
/**
|
||||
* @brief The SingleServer class This class is classic server with support all base server functions.
|
||||
* classic server support:
|
||||
* - ssl encryption
|
||||
* - ssl encryption (See the SslMode enum).
|
||||
* - multitrading working.
|
||||
* - user registration.
|
||||
* - working with dabase.
|
||||
* - user registration. (See The PKG::User class)
|
||||
* - working with dabase. (See the DBObject class)
|
||||
*
|
||||
* Examples
|
||||
*
|
||||
* \code{cpp}
|
||||
* \endcode
|
||||
* s
|
||||
*
|
||||
*/
|
||||
class SingleServer : public DataBaseNode
|
||||
{
|
||||
@ -80,6 +83,11 @@ protected:
|
||||
*/
|
||||
AccessToken generateToken(int duration = AccessToken::Day);
|
||||
|
||||
ParserResult parsePackage(const Package &pkg, const AbstractNodeInfo *sender) override;
|
||||
|
||||
private:
|
||||
bool workWithUserRequest(const PKG::User &obj, const Package &pkg, const AbstractNodeInfo *sender);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -109,10 +109,9 @@ protected:
|
||||
|
||||
/**
|
||||
* @brief defaultInitPararm This method retrun default pdrameters of the database.
|
||||
* @param initFile
|
||||
* @return
|
||||
* @return map of database params.
|
||||
*
|
||||
* * Support parameters of database:
|
||||
* * Support parameters of database:
|
||||
*
|
||||
* - DBDriver - This is sql driver of data base for more information see The Qt Documentatuons https://doc.qt.io/qt-5/sql-driver.html
|
||||
* - DBFilePath - This is path to file of data base (sqlite only). This is phusical location of sqlite database.
|
||||
|
Loading…
x
Reference in New Issue
Block a user