Backend Service

This commit is contained in:
2019-03-14 01:48:00 +00:00
parent 100aef6763
commit 4522319a38
3 changed files with 115 additions and 1 deletions
+10
View File
@@ -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
+97
View File
@@ -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 <string>
#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 && i<sz-1; i++ )
{
int k = seed%n;
if (seed>1 && 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 );
}
+8 -1
View File
@@ -13,6 +13,9 @@
#include <algorithm>
#include <cctype>
#include <locale>
/*
#include <stdio.h>
#include <stdlib.h>
@@ -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());