From 4522319a38e5c8f463f20f6941b9390b78053daa Mon Sep 17 00:00:00 2001 From: Olusesan Ameye Date: Thu, 14 Mar 2019 01:48:00 +0000 Subject: [PATCH] Backend Service --- mermsemr/src/include/common_tool.h | 10 ++ mermsemr/src/shared_tool/common_tool.cc | 97 ++++++++++++++++++++ mermsemr/src/shared_tool/function_members.cc | 9 +- 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 mermsemr/src/include/common_tool.h create mode 100644 mermsemr/src/shared_tool/common_tool.cc diff --git a/mermsemr/src/include/common_tool.h b/mermsemr/src/include/common_tool.h new file mode 100644 index 0000000..359eeb8 --- /dev/null +++ b/mermsemr/src/include/common_tool.h @@ -0,0 +1,10 @@ +#ifndef __mx_common_tool_h__ +#define __mx_common_tool_h__ + +#include "vars.h" + +//void Confirmation( unsigned long payment_id, char * number, int sz ); +void GetMemberAccountLink( long member_id, unsigned long acc_link, char * number); +void GenerateInnerConfirmationSeed( char * number, int sz, int seed ); +#endif + diff --git a/mermsemr/src/shared_tool/common_tool.cc b/mermsemr/src/shared_tool/common_tool.cc new file mode 100644 index 0000000..3e459a2 --- /dev/null +++ b/mermsemr/src/shared_tool/common_tool.cc @@ -0,0 +1,97 @@ +#include "common_tool.h" +#include "clog.h" +#include "cgi.h" +#include "input.h" +#include "mermsemr_api.h" +#include "safestring.h" +#include "cfg.h" +#include +#include "pgsql_wrapper.h" +#include "pgsql.h" + +//char confirmation[20] = ""; +//Confirmation(payment_id, confirmation, sizeof (confirmation)); + + + + +void GenerateInnerConfirmationSeed( char * number, int sz, int seed ) +{ + char chars[] = "WRB01234WRB56789WRB"; + int n = sizeof(chars); + int i; +/* + time_t t; + time( &t ); + pid_t pid = getpid(); + + srand(t+pid); +*/ + srand((unsigned int)time((time_t *)NULL)); + + for ( i=0; i<10 && i1 && k==i) { + number[i] = chars[n-k]; + } else { + number[i] = chars[ (int) ( (n-1.0)*rand()/(RAND_MAX+1.0)) ]; + } + } + number[i] = 0; +} + + + +void ConfirmationNew( unsigned long payment_id, char * number, int sz ) +{ + SQLINTEGER rows; + char confirmation[11]; + + // Lock table to prevent generation of two identical confirmation numbers + pgsql_exec("BEGIN; LOCK TABLE members_payments;" ); + int i = 0; + do + { + GenerateInnerConfirmationSeed( confirmation, sizeof(confirmation), i++ ); + + //st.CloseCursor(); + rows = 0; + const PGresult *res = pgsql_query("SELECT id FROM members_payments WHERE confirmation='%s'", confirmation ); + if (res!=NULL ) + { + rows = pgsql_num_rows(res); + } + } while ( rows>0 && i<100 ); + + pgsql_exec("UPDATE members_payments SET confirmation='%s', dt_confirmed=now() WHERE id=%lu", confirmation, payment_id ); + pgsql_exec("COMMIT" ); // Unlock table 'data' + strsafecpy( number, confirmation, sz ); +} + + +void GetMemberAccountLink( long member_id, unsigned long acc_link, char * number ) +{ + SQLINTEGER rows; + char offer_code[14]; + + // Lock table to prevent generation of two identical confirmation numbers + pgsql_exec("BEGIN; LOCK TABLE members_jobs_offer;" ); + int i = 0; + do + { + GenerateInnerConfirmationSeed( offer_code, sizeof(offer_code), i++ ); + + //st.CloseCursor(); + rows = 0; + const PGresult *res = pgsql_query("SELECT id FROM members WHERE offer_code='%s'", offer_code ); + if (res!=NULL ) + { + rows = pgsql_num_rows(res); + } + } while ( rows>0 && i<100 ); + + pgsql_exec("UPDATE members_jobs_offer SET acc_link='%s' WHERE id=%lu", offer_code, member_id ); + pgsql_exec("COMMIT" ); // Unlock table 'data' +// strsafecpy( acc_link, offer_code, sz ); +} diff --git a/mermsemr/src/shared_tool/function_members.cc b/mermsemr/src/shared_tool/function_members.cc index 19ee670..fe0f4ae 100644 --- a/mermsemr/src/shared_tool/function_members.cc +++ b/mermsemr/src/shared_tool/function_members.cc @@ -13,6 +13,9 @@ #include #include #include + + + /* #include #include @@ -21,7 +24,7 @@ /* -- */ #include "function_members.h" - +#include "common_tool.h" long MemberLogin(CVars in, CVars &out) { long ret = PHP_API_BAD_PARAM; @@ -40,6 +43,10 @@ long MemberLogin(CVars in, CVars &out) { if (MemberSessionCheck(out["member_id"].Long(), out["sessionid"].c_str(), 1) > 0) { out["acc_link"] = "ME345FT6789"; + char acc_link[11]; + // GetMemberAccountLink(out["member_id"].Long(),acc_link, sizeof (acc_link) ); + // out["acc_link"] = acc_link; + out["stauts"] = "OK"; /*LOAD THE SESSION INTO OUT now */ load_db_record(out, "SELECT session FROM members_session WHERE member_id=%lu ORDER BY id DESC LIMIT 1", out["member_id"].Long());