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
3 changes: 3 additions & 0 deletions Interfaces/AAA/AAADefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace tblUser {
}

constexpr quint64 MinNormalUserID = 100;

TARGOMAN_CREATE_CONSTEXPR(usrID);
TARGOMAN_CREATE_CONSTEXPR(usrGender);
TARGOMAN_CREATE_CONSTEXPR(usrName);
Expand All @@ -80,6 +81,8 @@ namespace tblUser {
TARGOMAN_CREATE_CONSTEXPR(usr_rolID);
TARGOMAN_CREATE_CONSTEXPR(usrSpecialPrivs);
TARGOMAN_CREATE_CONSTEXPR(usrLanguage);
TARGOMAN_CREATE_CONSTEXPR(usrEnableEmailAlerts);
TARGOMAN_CREATE_CONSTEXPR(usrEnableSMSAlerts);
TARGOMAN_CREATE_CONSTEXPR(usrMaxSessions);
TARGOMAN_CREATE_CONSTEXPR(usrActiveSessions);
TARGOMAN_CREATE_CONSTEXPR(usrLastLogin);
Expand Down
23 changes: 12 additions & 11 deletions Interfaces/Test/testCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,18 @@ class clsBaseTest : public QObject
// DAC.execQuery("", QString("DELETE FROM %1AAA.tblRoles WHERE rolName IN(?,?)").arg(this->DBPrefix), {UT_ServiceRoleName, UT_RoleName});

/*
DELETE FROM tblWalletsTransactions;
DELETE FROM tblWalletBalances;
DELETE FROM tblUserWallets;
DELETE FROM tblOnlinePayments;
DELETE FROM tblOfflinePayments;
DELETE FROM tblOfflinePaymentClaims;
DELETE FROM tblVoucher;
DELETE FROM tblApprovalRequest;
DELETE FROM tblActiveSessions;
DELETE FROM tblUser WHERE usrID > 100;
DELETE FROM tblRoles WHERE LOWER(rolName) LIKE '%test%'
DELETE FROM dev_AAA.tblWalletsTransactions;
DELETE FROM dev_AAA.tblWalletBalances;
DELETE FROM dev_AAA.tblUserWallets;
DELETE FROM dev_AAA.tblOnlinePayments;
DELETE FROM dev_AAA.tblOfflinePayments;
DELETE FROM dev_AAA.tblOfflinePaymentClaims;
DELETE FROM dev_AAA.tblVoucher;
DELETE FROM dev_AAA.tblApprovalRequest;
DELETE FROM dev_AAA.tblActiveSessions;
DELETE FROM dev_AAA.tblUser WHERE usrID > 100;
DELETE FROM dev_AAA.tblRoles WHERE LOWER(rolName) LIKE '%test%';
DELETE FROM dev_Common.tblAlerts;
*/
}
};
Expand Down
26 changes: 16 additions & 10 deletions Modules/Account/functionalTest/testAccount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ private slots:
{ "mobile", "0999-888-1010" },
{ "signupIfNotExists", true },
{ "signupRole", UT_RoleName },
{ "signupEnableEmailAlerts", false },
{ "signupEnableSMSAlerts", false },
})
;

Expand Down Expand Up @@ -328,11 +330,13 @@ private slots:
//df6d2338b2b8fce1ec2f6dda0a630eb0 # 987
QVERIFY((gUserID = callUserAPI(RESTClientHelper::PUT,
"Account/signup", {}, {
{"emailOrMobile", UT_UserEmail},
{"name", "unit"},
{"family", "test"},
{"pass", "df6d2338b2b8fce1ec2f6dda0a630eb0"},
{"role", UT_RoleName}
{ "emailOrMobile", UT_UserEmail },
{ "name", "unit" },
{ "family", "test" },
{ "pass", "df6d2338b2b8fce1ec2f6dda0a630eb0" },
{ "role", UT_RoleName },
{ "enableEmailAlerts", false },
{ "enableSMSAlerts", false },
})
.toMap()
.value("usrID")
Expand All @@ -342,11 +346,13 @@ private slots:
//df6d2338b2b8fce1ec2f6dda0a630eb0 # 987
QVERIFY((gAdminUserID = callUserAPI(RESTClientHelper::PUT,
"Account/signup", {}, {
{"emailOrMobile", UT_AdminUserEmail},
{"name", "admin unit"},
{"family", "test"},
{"pass", "df6d2338b2b8fce1ec2f6dda0a630eb0"},
{"role", UT_RoleName}
{ "emailOrMobile", UT_AdminUserEmail },
{ "name", "admin unit" },
{ "family", "test" },
{ "pass", "df6d2338b2b8fce1ec2f6dda0a630eb0" },
{ "role", UT_RoleName },
{ "enableEmailAlerts", false },
{ "enableSMSAlerts", false },
})
.toMap()
.value("usrID")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Migration File: m20220425_105147_AAA_review_userwallets.sql */

/* CAUTION: don't forget to use {{dbprefix}} for schemas */

ALTER TABLE `tblWalletsTransactions`
DROP INDEX `wltType`,
Expand Down
66 changes: 17 additions & 49 deletions Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ QVariantMap Account::apiPUTsignup(
QString _role,
QString _name,
QString _family,
bool _enableEmailAlerts,
bool _enableSMSAlerts,
TAPI::JSON_t _specialPrivs,
qint8 _maxSessions
) {
Expand Down Expand Up @@ -313,6 +315,8 @@ QVariantMap Account::apiPUTsignup(
{ "iSpecialPrivs", _specialPrivs.isEmpty()? QVariant() : _specialPrivs },
{ "iMaxSessions", _maxSessions },
{ "iCreatorUserID", QVariant() },
{ "iEnableEmailAlerts", _enableEmailAlerts ? 1 : 0 },
{ "iEnableSMSAlerts", _enableSMSAlerts ? 1 : 0 },
})
.spDirectOutputs()
.value("oUserID")
Expand All @@ -323,51 +327,7 @@ QVariantMap Account::apiPUTsignup(
{ "usrID", UserID },
};
}
/*
QVariantMap Account::apiPUTsignupByMobileOnly(
TAPI::Mobile_t _mobile,
// quint32 _verifyCode,
// TAPI::MD5_t _pass,
QString _role,
QString _name,
QString _family,
TAPI::JSON_t _specialPrivs,
qint8 _maxSessions
) {
Authorization::validateIPAddress(_APICALLBOOM.getIP());

if (QFV.mobile().isValid(_mobile) == false)
throw exHTTPBadRequest("Incorrect mobile.");

_mobile = PhoneHelper::NormalizePhoneNumber(_mobile);

QFV.asciiAlNum().maxLenght(50).validate(_role);

if (_role.toLower() == "administrator" || _role.toLower() == "system" || _role.toLower() == "baseuser")
throw exHTTPForbidden("Selected role is not allowed to signup");

quint64 UserID = this->callSP("spSignup", {
{ "iBy", "M" },
{ "iLogin", _mobile },
{ "iPass", "" },
{ "iRole", _role },
{ "iIP", _APICALLBOOM.getIP() },
{ "iName", _name.isEmpty()? QVariant() : _name },
{ "iFamily", _family.isEmpty()? QVariant() : _family },
{ "iSpecialPrivs", _specialPrivs.isEmpty()? QVariant() : _specialPrivs },
{ "iMaxSessions", _maxSessions },
{ "iCreatorUserID", QVariant() },
})
.spDirectOutputs()
.value("oUserID")
.toDouble();

return {
{ "type", "mobile" },
{ "usrID", UserID },
};
}
*/
TAPI::EncodedJWT_t Account::apiPOSTapproveEmail(
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
QString _email,
Expand Down Expand Up @@ -493,7 +453,9 @@ bool Account::apiloginByMobileOnly(
APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM,
TAPI::Mobile_t _mobile,
bool _signupIfNotExists,
QString _signupRole
QString _signupRole,
bool _signupEnableEmailAlerts,
bool _signupEnableSMSAlerts
) {
Authorization::validateIPAddress(_APICALLBOOM.getIP());

Expand All @@ -514,6 +476,8 @@ bool Account::apiloginByMobileOnly(
{ "iMobile", _mobile },
{ "iSignupIfNotExists", _signupIfNotExists ? 1 : 0 },
{ "iSignupRole", _signupRole },
{ "iSignupEnableEmailAlerts", _signupEnableEmailAlerts ? 1 : 0 },
{ "iSignupEnableSMSAlerts", _signupEnableSMSAlerts ? 1 : 0 },
});

return true;
Expand Down Expand Up @@ -648,7 +612,7 @@ QString Account::apicreateForgotPasswordLink(

this->callSP("spForgotPass_Request", {
{ "iLogin", _emailOrMobile },
{ "iVia", Type },
{ "iBy", Type },
});

return (Type == "E" ? "email" : "mobile");
Expand Down Expand Up @@ -702,7 +666,7 @@ bool Account::apichangePassByUUID(
QString Type = PhoneHelper::ValidateAndNormalizeEmailOrPhoneNumber(_emailOrMobile);

this->callSP("spPassword_ChangeByCode", {
{ "iVia", Type },
{ "iBy", Type },
{ "iLogin", _emailOrMobile },
{ "iCode", _uuid },
{ "iNewPass", _newPass },
Expand Down Expand Up @@ -1399,7 +1363,9 @@ QVariant Account::apiPOSTfixtureSetup(
{ "df6d2338b2b8fce1ec2f6dda0a630eb0" },
RoleName,
"fixture test",
"user"
"user",
false,
false
);

SignupUserResult.insert("email", UserEmail);
Expand Down Expand Up @@ -1456,7 +1422,9 @@ QVariant Account::apiPOSTfixtureSetup(
{ "df6d2338b2b8fce1ec2f6dda0a630eb0" },
RoleName,
"fixture test",
"admin"
"admin",
false,
false
);

SignupAdminUserResult.insert("email", AdminUserEmail);
Expand Down
24 changes: 5 additions & 19 deletions Modules/Account/moduleSrc/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,14 @@ private slots:
QString _role = "BaseUser",
QString _name = "",
QString _family = "",
bool _enableEmailAlerts = true,
bool _enableSMSAlerts = true,
TAPI::JSON_t _specialPrivs = {},
qint8 _maxSessions = -1
),
"Base method for signup with email or mobile. this method can be called just by predefined IPs"
)

/*
QVariantMap REST_PUT(
signupByMobileOnly,
(
APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM,
TAPI::Mobile_t _mobile,
QString _role = "BaseUser",
QString _name = "",
QString _family = "",
TAPI::JSON_t _specialPrivs = {},
qint8 _maxSessions = -1
),
"Base method for signup with mobile only. this method can be called just by predefined IPs"
)
*/
// "If verifyCode is empty, a new random code is generated and sent to the user via SMS."
// "After the user submits this code, signupByMobile must be called again with verifyCode."

TAPI::EncodedJWT_t REST_POST(
approveEmail,
(
Expand Down Expand Up @@ -172,7 +156,9 @@ private slots:
APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM,
TAPI::Mobile_t _mobile,
bool _signupIfNotExists = false,
QString _signupRole = "BaseUser"
QString _signupRole = "BaseUser",
bool _signupEnableEmailAlerts = true,
bool _signupEnableSMSAlerts = true
// quint32 _verifyCode = 0/* = {}*/,
// TAPI::MD5_t _pass = {},
// QString _salt = {},
Expand Down
60 changes: 34 additions & 26 deletions Modules/Account/moduleSrc/ORM/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,33 @@ User::User() :
intfSQLBasedModule(
AAASchema,
tblUser::Name,
{///< ColName Type Validation Default UpBy Sort Filter Self Virt PK
{///< ColName Type Validation Default UpBy Sort Filter Self Virt PK
//ORM_PRIMARYKEY_64 with self:true
{ tblUser::usrID, S(quint64), QFV.integer().minValue(1), QAuto, UPNone, true, true, true, false, true },
{ tblUser::usrEmail, S(TAPI::Email_t), QFV.emailNotFake(), QNull, UPOwner },
{ tblUser::usrName, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner },
{ tblUser::usrFamily, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner },
{ tblUser::usrGender, S(TAPI::enuGender::Type), QFV, TAPI::enuGender::NotExpressed, UPOwner },
{ tblUser::usrMobile, S(TAPI::Mobile_t), QFV, QNull, UPOwner },
{ tblUser::usrApprovalState, S(TAPI::enuUserApproval::Type), QFV, TAPI::enuUserApproval::None },
{ tblUser::usrID, S(quint64), QFV.integer().minValue(1), QAuto, UPNone, true, true, true, false, true },
{ tblUser::usrEmail, S(TAPI::Email_t), QFV.emailNotFake(), QNull, UPOwner },
{ tblUser::usrName, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner },
{ tblUser::usrFamily, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner },
{ tblUser::usrGender, S(TAPI::enuGender::Type), QFV, TAPI::enuGender::NotExpressed, UPOwner },
{ tblUser::usrMobile, S(TAPI::Mobile_t), QFV, QNull, UPOwner },
{ tblUser::usrApprovalState, S(TAPI::enuUserApproval::Type), QFV, TAPI::enuUserApproval::None },
//{ tblUser::usrPass,
{ tblUser::usr_rolID, S(quint32), QFV.integer().minValue(1), QRequired, UPAdmin },
{ tblUser::usrSpecialPrivs, S(TAPI::PrivObject_t), QFV, QNull, UPAdmin, false, false },
{ tblUser::usrLanguage, S(QString), QFV.languageCode(), "fa", UPOwner },
{ tblUser::usrMaxSessions, S(qint32), QFV.integer().betweenValues(-1, 100), -1, UPAdmin },
{ tblUser::usrActiveSessions, S(qint32), QFV.integer().betweenValues(-1, 1000), QInvalid, UPNone },
{ tblUser::usrLastLogin, S(TAPI::DateTime_t), QFV, QInvalid, UPNone },
{ tblUser::usrStatus, ORM_STATUS_FIELD(TAPI::enuUserStatus, TAPI::enuUserStatus::MustValidate) },
{ tblUser::usr_rolID, S(quint32), QFV.integer().minValue(1), QRequired, UPAdmin },
{ tblUser::usrSpecialPrivs, S(TAPI::PrivObject_t), QFV, QNull, UPAdmin, false, false },
{ tblUser::usrLanguage, S(QString), QFV.languageCode(), "fa", UPOwner },
{ tblUser::usrEnableEmailAlerts, S(bool), QFV, true, UPOwner },
{ tblUser::usrEnableSMSAlerts, S(bool), QFV, true, UPOwner },
{ tblUser::usrMaxSessions, S(qint32), QFV.integer().betweenValues(-1, 100), -1, UPAdmin },
{ tblUser::usrActiveSessions, S(qint32), QFV.integer().betweenValues(-1, 1000), QInvalid, UPNone },
{ tblUser::usrLastLogin, S(TAPI::DateTime_t), QFV, QInvalid, UPNone },
{ tblUser::usrStatus, ORM_STATUS_FIELD(TAPI::enuUserStatus, TAPI::enuUserStatus::MustValidate) },
{ ORM_INVALIDATED_AT_FIELD },
{ tblUser::usrCreationDateTime, ORM_CREATED_ON },
{ tblUser::usrCreatedBy_usrID, ORM_CREATED_BY_NULLABLE },
{ tblUser::usrUpdatedBy_usrID, ORM_UPDATED_BY },
{ tblUser::usrCreationDateTime, ORM_CREATED_ON },
{ tblUser::usrCreatedBy_usrID, ORM_CREATED_BY_NULLABLE },
{ tblUser::usrUpdatedBy_usrID, ORM_UPDATED_BY },
},
{///< Col Reference Table ForeignCol Rename LeftJoin
{ tblUser::usr_rolID, R(AAASchema, tblRoles::Name), tblRoles::rolID },
{ tblUser::Relation::ExtraInfo, { tblUser::usrID, R(AAASchema, tblUserExtraInfo::Name), tblUserExtraInfo::uei_usrID, "", true } },
{///< Col Reference Table ForeignCol Rename LeftJoin
{ tblUser::usr_rolID, R(AAASchema, tblRoles::Name), tblRoles::rolID },
{ tblUser::Relation::ExtraInfo, { tblUser::usrID, R(AAASchema, tblUserExtraInfo::Name), tblUserExtraInfo::uei_usrID, "", true } },
ORM_RELATION_OF_CREATOR(tblUser::usrCreatedBy_usrID),
ORM_RELATION_OF_UPDATER(tblUser::usrUpdatedBy_usrID),
},
Expand Down Expand Up @@ -110,6 +112,8 @@ QVariant User::apiGET(GET_METHOD_ARGS_IMPL_APICALL) {
tblUser::usr_rolID,
// tblUser::usrSpecialPrivs,
tblUser::usrLanguage,
tblUser::usrEnableEmailAlerts,
tblUser::usrEnableSMSAlerts,
// tblUser::usrMaxSessions,
tblUser::usrActiveSessions,
tblUser::usrLastLogin,
Expand Down Expand Up @@ -325,16 +329,20 @@ bool User::apiUPDATEpersonalInfo(
QString _name,
QString _family,
TAPI::ISO639_2_t _language,
NULLABLE_TYPE(TAPI::enuGender::Type) _gender
NULLABLE_TYPE(TAPI::enuGender::Type) _gender,
NULLABLE_TYPE(bool) _enableEmailAlerts,
NULLABLE_TYPE(bool) _enableSMSAlerts
) {
quint64 CurrentUserID = _APICALLBOOM.getUserID();

QVariantMap ToUpdate;

if (_name.isNull() == false) ToUpdate.insert(tblUser::usrName, _name);
if (_family.isNull() == false) ToUpdate.insert(tblUser::usrFamily, _family);
if (_language.isNull() == false) ToUpdate.insert(tblUser::usrLanguage, _language);
if (NULLABLE_HAS_VALUE(_gender)) ToUpdate.insert(tblUser::usrGender, *_gender);
if (_name.isNull() == false) ToUpdate.insert(tblUser::usrName, _name);
if (_family.isNull() == false) ToUpdate.insert(tblUser::usrFamily, _family);
if (_language.isNull() == false) ToUpdate.insert(tblUser::usrLanguage, _language);
if (NULLABLE_HAS_VALUE(_gender)) ToUpdate.insert(tblUser::usrGender, *_gender);
if (NULLABLE_HAS_VALUE(_enableEmailAlerts)) ToUpdate.insert(tblUser::usrEnableEmailAlerts, *_enableEmailAlerts ? 1 : 0);
if (NULLABLE_HAS_VALUE(_enableSMSAlerts)) ToUpdate.insert(tblUser::usrEnableSMSAlerts, *_enableSMSAlerts ? 1 : 0);

if (ToUpdate.size())
this->Update(*this,
Expand Down
4 changes: 3 additions & 1 deletion Modules/Account/moduleSrc/ORM/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ private slots:
QString _name = {},
QString _family = {},
TAPI::ISO639_2_t _language = {},
NULLABLE_TYPE(TAPI::enuGender::Type) _gender = {}
NULLABLE_TYPE(TAPI::enuGender::Type) _gender = {},
NULLABLE_TYPE(bool) _enableEmailAlerts = {},
NULLABLE_TYPE(bool) _enableSMSAlerts = {}
),
"Update User personal info"
)
Expand Down
Loading