diff --git a/src/app/Deal.cpp b/src/app/Deal.cpp index 8adc4fd..c9d8f70 100644 --- a/src/app/Deal.cpp +++ b/src/app/Deal.cpp @@ -140,6 +140,11 @@ namespace Apostol { DateTimeToStr(Value, Buffer, sizeof(Buffer), Format.c_str()); return Buffer; } + //-------------------------------------------------------------------------------------------------------------- + + CString GenSalt() { + return GetUID(9).Lower(); + } //-------------------------------------------------------------------------------------------------------------- @@ -172,8 +177,8 @@ namespace Apostol { return doCompleted; } else if (S == "cancel") { return doCancel; - } else if (S == "canceled") { - return doCanceled; + } else if (S == "canceled" || S == "cancelled") { + return doCancelled; } else if (S == "execute") { return doExecute; } else if (S == "executed") { @@ -218,8 +223,8 @@ namespace Apostol { return "Completed"; case doCancel: return "Cancel"; - case doCanceled: - return "Canceled"; + case doCancelled: + return "Cancelled"; case doExecute: return "Execute"; case doExecuted: @@ -318,6 +323,9 @@ namespace Apostol { Data += S.Format("Sum: %s;", Payment.Sum.c_str()); Data += S.Format("LeaveBefore: %s", FeedBack.LeaveBefore.c_str()); + if (!Salt.IsEmpty()) + Data += S.Format("Salt: %s", Salt.c_str()); + return Data; } @@ -532,7 +540,9 @@ namespace Apostol { if (VerifyDate(date, Date) != 1) throw ExceptionFrm("Invalid deal date format: %s.", date.c_str()); - m_Data.Date = DateToString(Date); + m_Data.Date = UTCFormat(DateToString(Date)); + + m_Data.Salt = deal["salt"].as(); const auto& seller = deal["seller"]; m_Data.Seller.Address = seller["address"].as(); @@ -570,7 +580,7 @@ namespace Apostol { if (VerifyDate(until, Until) != 1) throw ExceptionFrm("Invalid until date format: %s.", until.c_str()); - m_Data.Payment.Until = DateToString(Until); + m_Data.Payment.Until = UTCFormat(DateToString(Until)); } const auto &sum = payment["sum"].as(); @@ -590,7 +600,7 @@ namespace Apostol { if (VerifyDate(leave_before, LeaveBefore) != 1) throw ExceptionFrm("Invalid leave before date format: %s.", leave_before.c_str()); - m_Data.FeedBack.LeaveBefore = DateToString(LeaveBefore); + m_Data.FeedBack.LeaveBefore = UTCFormat(DateToString(LeaveBefore)); } if (feedback["status"]) @@ -614,10 +624,10 @@ namespace Apostol { } if (m_Data.Payment.Until.IsEmpty()) - m_Data.Payment.Until = DateToString(Date + 1); // 1 day + m_Data.Payment.Until = UTCFormat(DateToString(Date + 1)); // 1 day if (m_Data.FeedBack.LeaveBefore.IsEmpty()) - m_Data.FeedBack.LeaveBefore = DateToString(Date + 14); // 14 day + m_Data.FeedBack.LeaveBefore = UTCFormat(DateToString(Date + 14)); // 14 day m_Data.Code = GetCode(); } else diff --git a/src/app/Deal.hpp b/src/app/Deal.hpp index 20df2ee..fd1927c 100644 --- a/src/app/Deal.hpp +++ b/src/app/Deal.hpp @@ -41,9 +41,15 @@ namespace Apostol { double BTCToDouble(const CString &Value); CString DoubleToBTC(const double &Value, const CString &Format = _T("%f BTC")); + //-------------------------------------------------------------------------------------------------------------- CDateTime StringToDate(const CString &Value, const CString &Format = _T("%04d-%02d-%02d %02d:%02d:%02d")); - CString DateToString(CDateTime Value, const CString &Format = _T("%Y-%m-%d %H:%M:%S UTC")); + CString DateToString(CDateTime Value, const CString &Format = _T("%Y-%m-%d %H:%M:%S")); + + int VerifyDate(const CString &Date, CDateTime &Result); + //-------------------------------------------------------------------------------------------------------------- + + CString GenSalt(); //-------------------------------------------------------------------------------------------------------------- @@ -162,8 +168,8 @@ namespace Apostol { enum CFeedBackStatus { fsNegative = -1, fsNeutral = 0, fsPositive = 1 }; //-------------------------------------------------------------------------------------------------------------- - enum CDealOrder { doCreate = 0, doCreated, doSubmit, doSubmitted, doConfirm, doConfirmed, doPay, doPaid, doComplete, doCompleted, doCancel, doCanceled, - doExecute, doExecuted, doDelete, doDeleted, doFail, doFailed, doFeedback }; + enum CDealOrder { doCreate = 0, doCreated, doSubmit, doSubmitted, doConfirm, doConfirmed, doPay, doPaid, doComplete, doCompleted, doCancel, doCancelled, + doExecute, doExecuted, doDelete, doDeleted, doFail, doFailed, doFeedback }; //-------------------------------------------------------------------------------------------------------------- typedef struct DealData { @@ -173,6 +179,7 @@ namespace Apostol { // Hidden value CString Code {}; + CString Salt {}; CString At {}; CString Date {}; @@ -233,6 +240,9 @@ namespace Apostol { RM.Object().AddPair("at", LS.At); RM.Object().AddPair("date", LS.Date); + if (!LS.Salt.IsEmpty()) + RM.Object().AddPair("salt", LS.Salt); + CJSON jsonSeller(jvtObject); jsonSeller.Object().AddPair("address", LS.Seller.Address); diff --git a/src/modules/Workers/WebService/WebService.cpp b/src/modules/Workers/WebService/WebService.cpp index 80dd0ff..e8caa5b 100644 --- a/src/modules/Workers/WebService/WebService.cpp +++ b/src/modules/Workers/WebService/WebService.cpp @@ -519,6 +519,7 @@ namespace Apostol { const auto &formType = FormData["type"]; const auto &formAt = FormData["at"]; const auto &formDate = FormData["date"]; + const auto &formSalt = FormData["salt"]; const auto &formSellerAddress = FormData["seller_address"]; const auto &formSellerRating = FormData["seller_rating"]; const auto &formSellerSignature = FormData["seller_signature"]; @@ -536,7 +537,6 @@ namespace Apostol { CheckKeyForNull("order", Action.c_str()); CheckKeyForNull("type", formType.c_str()); CheckKeyForNull("at", formAt.c_str()); - //CheckKeyForNull("date", formDate.c_str()); CheckKeyForNull("seller_address", formSellerAddress.c_str()); CheckKeyForNull("customer_address", formCustomerAddress.c_str()); CheckKeyForNull("payment_sum", formPaymentSum.c_str()); @@ -556,6 +556,7 @@ namespace Apostol { Deal["at"] = formAt.c_str(); Deal["date"] = formDate.IsEmpty() ? UTCFormat(DateToString(UTC())).c_str() : formDate.c_str(); + Deal["salt"] = formSalt.IsEmpty() ? GenSalt().c_str() : formSalt.c_str(); YAML::Node Seller = Deal["seller"]; @@ -610,6 +611,7 @@ namespace Apostol { const auto &formType = FormData.Data("type"); const auto &formAt = FormData.Data("at"); const auto &formDate = FormData.Data("date"); + const auto &formSalt = FormData.Data("salt"); const auto &formSellerAddress = FormData.Data("seller_address"); const auto &formSellerRating = FormData.Data("seller_rating"); const auto &formSellerSignature = FormData.Data("seller_signature"); @@ -627,7 +629,6 @@ namespace Apostol { CheckKeyForNull("order", Action.c_str()); CheckKeyForNull("type", formType.c_str()); CheckKeyForNull("at", formAt.c_str()); - //CheckKeyForNull("date", formDate.c_str()); CheckKeyForNull("seller_address", formSellerAddress.c_str()); CheckKeyForNull("customer_address", formCustomerAddress.c_str()); CheckKeyForNull("payment_sum", formPaymentSum.c_str()); @@ -647,6 +648,7 @@ namespace Apostol { Deal["at"] = formAt.c_str(); Deal["date"] = formDate.IsEmpty() ? UTCFormat(DateToString(UTC())).c_str() : formDate.c_str(); + Deal["salt"] = formSalt.IsEmpty() ? GenSalt().c_str() : formSalt.c_str(); YAML::Node Seller = Deal["seller"]; @@ -702,6 +704,7 @@ namespace Apostol { const auto &formAt = jsonData["at"].AsString(); const auto &formDate = jsonData["date"].AsString(); + const auto &formSalt = jsonData["salt"].AsString(); const CJSONValue &jsonSeller = jsonData["seller"]; @@ -733,7 +736,6 @@ namespace Apostol { CheckKeyForNull("order", action.c_str()); CheckKeyForNull("type", formType.c_str()); CheckKeyForNull("at", formAt.c_str()); - //CheckKeyForNull("date", formDate.c_str()); CheckKeyForNull("seller.address", formSellerAddress.c_str()); CheckKeyForNull("customer.address", formCustomerAddress.c_str()); CheckKeyForNull("payment.sum", formPaymentSum.c_str()); @@ -753,6 +755,7 @@ namespace Apostol { Deal["at"] = formAt.c_str(); Deal["date"] = formDate.IsEmpty() ? UTCFormat(DateToString(UTC())).c_str() : formDate.c_str(); + Deal["salt"] = formSalt.IsEmpty() ? GenSalt().c_str() : formSalt.c_str(); YAML::Node Seller = Deal["seller"];