Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ ALTER TABLE `tblOfflinePaymentClaims`
DROP FOREIGN KEY `FK_tblOfflinePaymentClaims_tblUser_creator`,
DROP FOREIGN KEY `FK_tblOfflinePaymentClaims_tblUser_modifier`;

RENAME TABLE `tblOfflinePaymentClaims` TO `DELETED_tblOfflinePaymentClaims`;
-- will be dropped in next minor version
-- DROP TABLE tblOfflinePaymentClaims;
DROP TABLE tblOfflinePaymentClaims;

DROP TRIGGER IF EXISTS `trg_tblOfflinePayments_before_update`;
DELIMITER ;;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Migration File: m20220911_162331_AAA_create_tokenbin.sql */
/* CAUTION: don't forget to use {{dbprefix}} for schemas */

/* The next line is to prevent this file from being committed. When done, delete this and next line: */
ERROR("THIS MIGRATION FILE IS NOT READY FOR EXECUTE.")

USE `{{dbprefix}}{{Schema}}`;

CREATE TABLE `tblTokenBin` (
`tkbID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`tkbToken` TEXT NOT NULL COLLATE 'utf8mb4_general_ci',
`tkbTokenExpiredAt` DATETIME NOT NULL,
`tkbBlockedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`tkbBlockedBy_usrID` BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY (`tkbID`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
2 changes: 2 additions & 0 deletions Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "ORM/BlockingRules.h"
#include "ORM/ForgotPassRequest.h"
#include "ORM/IPBin.h"
#include "ORM/TokenBin.h"
#include "ORM/Roles.h"
#include "ORM/IPStats.h"
#include "ORM/Payments.h"
Expand Down Expand Up @@ -168,6 +169,7 @@ Account::Account() :
this->addSubModule(&ForgotPassRequest::instance());
this->addSubModule(&Voucher::instance());
this->addSubModule(&IPBin::instance());
this->addSubModule(&TokenBin::instance());
this->addSubModule(&IPStats::instance());
this->addSubModule(&PaymentGatewayTypes::instance());
this->addSubModule(&PaymentGateways::instance());
Expand Down
39 changes: 39 additions & 0 deletions Modules/Account/moduleSrc/ORM/APITokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ ORMSelectQuery APITokens::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBOOM_PARA
}

QVariant IMPL_ORMGET_USER(APITokens) {
APITokenServices::instance().prepareFiltersList();

if (Authorization::hasPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName())) == false)
this->setSelfFilters({{tblAPITokens::Fields::apt_usrID, APICALLBOOM_PARAM.getActorID()}}, _filters);

Expand Down Expand Up @@ -230,6 +232,43 @@ Targoman::API::AccountModule::stuRequestTokenResult IMPL_REST_GET_OR_POST(APITok
);
}

QString IMPL_REST_GET_OR_POST(APITokens, revoke, (
APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM,
const QString &_token
)) {
QString TokenMD5 = QCryptographicHash::hash(_token.toLatin1(), QCryptographicHash::Md5).toHex().constData();

//TokenBin::instance().
// return this->create(
// APICALLBOOM_PARAM,
// APICALLBOOM_PARAM.getActorID(),
// _name,
// _services
// );
}

bool IMPL_REST_GET_OR_POST(APITokens, pause, (
APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM,
const QString &_token
)) {
QString TokenMD5 = QCryptographicHash::hash(_token.toLatin1(), QCryptographicHash::Md5).toHex().constData();

throw exHTTPMethodNotAllowed("Not implemented yet");

return true;
}

bool IMPL_REST_GET_OR_POST(APITokens, resume, (
APICALLBOOM_TYPE_JWT_USER_IMPL &APICALLBOOM_PARAM,
const QString &_token
)) {
QString TokenMD5 = QCryptographicHash::hash(_token.toLatin1(), QCryptographicHash::Md5).toHex().constData();

throw exHTTPMethodNotAllowed("Not implemented yet");

return true;
}

/******************************************************/
TARGOMAN_API_SUBMODULE_IMPLEMENT(Account, APITokenServices)

Expand Down
29 changes: 28 additions & 1 deletion Modules/Account/moduleSrc/ORM/APITokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,34 @@ private slots:
const QStringList &_services = {}
),
"create new empty api token"
)
);

QString REST_GET_OR_POST(
revoke,
(
APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM,
const QString &_token
),
"Deletes the token and creates a new one. It also takes the possibility of activity from the previous token"
);

bool REST_GET_OR_POST(
pause,
(
APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM,
const QString &_token
),
"Pause the token"
);

bool REST_GET_OR_POST(
resume,
(
APICALLBOOM_TYPE_JWT_USER_DECL &APICALLBOOM_PARAM,
const QString &_token
),
"Resume the paused token"
);

};

Expand Down
6 changes: 1 addition & 5 deletions Modules/Account/moduleSrc/ORM/IPBin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

#include "IPBin.h"
#include "User.h"
//#include "User.h"
#include "../Account.h"

TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AccountModule, enuIPBinStatus);
Expand All @@ -44,10 +44,6 @@ QVariant IMPL_ORMGET_USER(IPBin) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName()));

return this->Select(GET_METHOD_ARGS_CALL_VALUES);

// return query.one();

// return this->selectFromTable({}, {}, GET_METHOD_CALL_ARGS_APICALL);
}

} //namespace Targoman::API::AccountModule::ORM
1 change: 0 additions & 1 deletion Modules/Account/moduleSrc/ORM/IPBin.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ namespace tblIPBin {
}
#pragma GCC diagnostic pop


class IPBin : public intfSQLBasedModule
{
Q_OBJECT
Expand Down
49 changes: 49 additions & 0 deletions Modules/Account/moduleSrc/ORM/TokenBin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include "TokenBin.h"
//#include "User.h"
#include "../Account.h"

//TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AccountModule, enuTokenBinStatus);

namespace Targoman::API::AccountModule::ORM {

TARGOMAN_API_SUBMODULE_IMPLEMENT(Account, TokenBin)

TokenBin::TokenBin() :
intfSQLBasedModule(
AAASchema,
tblTokenBin::Name,
tblTokenBin::Private::ORMFields,
tblTokenBin::Private::Relations,
tblTokenBin::Private::Indexes
) { ; }

QVariant IMPL_ORMGET_USER(TokenBin) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_GET, this->moduleBaseName()));

return this->Select(GET_METHOD_ARGS_CALL_VALUES);
}

} //namespace Targoman::API::AccountModule::ORM
99 changes: 99 additions & 0 deletions Modules/Account/moduleSrc/ORM/TokenBin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#ifndef TARGOMAN_API_MODULES_ACCOUNT_ORM_TOKENBIN_H
#define TARGOMAN_API_MODULES_ACCOUNT_ORM_TOKENBIN_H

#include "Interfaces/AAA/AAA.hpp"
#include "Interfaces/API/intfSQLBasedModule.h"

namespace Targoman::API::AccountModule {
//structures and enumes goes here

} //namespace Targoman::API::AccountModule

//TAPI_DECLARE_METATYPE_ENUM(Targoman::API::AccountModule, enu...);

namespace Targoman::API::AccountModule {
namespace ORM {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace tblTokenBin {
constexpr char Name[] = "tblTokenBin";

namespace Fields {
TARGOMAN_CREATE_CONSTEXPR(tkbID);
TARGOMAN_CREATE_CONSTEXPR(tkbTokenMD5);
TARGOMAN_CREATE_CONSTEXPR(tkbTokenExpiredAt);
TARGOMAN_CREATE_CONSTEXPR(tkbBlockedAt);
TARGOMAN_CREATE_CONSTEXPR(tkbBlockedBy_usrID);
}

namespace Relation {
// constexpr char AAA[] = "aaa";
}

namespace Private {
const QList<clsORMField> ORMFields = {
//ColName Type Validation Default UpBy Sort Filter Self Virt PK
{ Fields::tkbID, ORM_PRIMARYKEY_64 },
{ Fields::tkbTokenMD5, S(TAPI::MD5_t), QFV, QRequired, UPNone },
{ Fields::tkbTokenExpiredAt, S(TAPI::DateTime_t), QFV, QRequired, UPNone },
{ Fields::tkbBlockedAt, ORM_CREATED_ON },
{ Fields::tkbBlockedBy_usrID, ORM_CREATED_BY },
};

const QList<stuRelation> Relations = {
//Col Reference Table ForeignCol Rename LeftJoin
{ Fields::tkbBlockedBy_usrID, R(AAASchema, tblUser::Name), tblUser::Fields::usrID, "Blocker_", true },
};

const QList<stuDBIndex> Indexes = {
};

} //namespace Private

TAPI_DEFINE_STRUCT(DTO,
SF_ORM_PRIMARYKEY_64 (tkbID),
SF_MD5_t (tkbTokenMD5),
SF_DateTime_t (tkbTokenExpiredAt),
SF_ORM_CREATED_ON (tkbBlockedAt),
SF_ORM_CREATED_BY (tkbBlockedBy_usrID)
);
}
#pragma GCC diagnostic pop

class TokenBin : public intfSQLBasedModule
{
Q_OBJECT
TARGOMAN_API_SUBMODULE_DEFINE(Account, TokenBin)

private slots:
QVariant ORMGET_USER("Get TokenBin information")
};

} //namespace ORM
} //namespace Targoman::API::AccountModule

#endif // TARGOMAN_API_MODULES_ACCOUNT_ORM_TOKENBIN_H
2 changes: 2 additions & 0 deletions Modules/Account/moduleSrc/moduleSrc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ HEADERS += \
ORM/IPBin.h \
ORM/IPStats.h \
ORM/PaymentGateways.h \
ORM/TokenBin.h \
ORM/User.h \
ORM/UserWallets.h \
ORM/WalletTransactions.h \
Expand Down Expand Up @@ -48,6 +49,7 @@ SOURCES += \
ORM/IPBin.cpp \
ORM/IPStats.cpp \
ORM/PaymentGateways.cpp \
ORM/TokenBin.cpp \
ORM/User.cpp \
ORM/UserWallets.cpp \
ORM/WalletTransactions.cpp \
Expand Down
13 changes: 13 additions & 0 deletions Modules/MT/functionalTest/testMT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ private slots:
}
}

void get_tokens() {
QT_TRY {
QVariant Result = this->callUserAPI(
RESTClientHelper::enuHTTPMethod::GET,
"Account/APITokens");

QVERIFY(Result.isValid());

} QT_CATCH (const std::exception &exp) {
QTest::qFail(exp.what(), __FILE__, __LINE__);
}
}

void addToBasket_1() {
QT_TRY {
int ItemsCount = this->LastPreVoucher.Items.length();
Expand Down
2 changes: 1 addition & 1 deletion Modules/TargomanMT/functionalTest/functionalTest.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Redistribution and use in source and binary forms are allowed under the
# terms of BSD License 2.0.
################################################################################
TEST_NAME = targomanFunctionalTest
TEST_NAME = targomanmtFunctionalTest

HEADERS += \
testTargomanMT.hpp
Expand Down