Backend Service
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
@@ -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 );
|
||||||
|
}
|
||||||
@@ -13,6 +13,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -21,7 +24,7 @@
|
|||||||
|
|
||||||
/* -- */
|
/* -- */
|
||||||
#include "function_members.h"
|
#include "function_members.h"
|
||||||
|
#include "common_tool.h"
|
||||||
|
|
||||||
long MemberLogin(CVars in, CVars &out) {
|
long MemberLogin(CVars in, CVars &out) {
|
||||||
long ret = PHP_API_BAD_PARAM;
|
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) {
|
if (MemberSessionCheck(out["member_id"].Long(), out["sessionid"].c_str(), 1) > 0) {
|
||||||
|
|
||||||
out["acc_link"] = "ME345FT6789";
|
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";
|
out["stauts"] = "OK";
|
||||||
/*LOAD THE SESSION INTO OUT now */
|
/*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());
|
load_db_record(out, "SELECT session FROM members_session WHERE member_id=%lu ORDER BY id DESC LIMIT 1", out["member_id"].Long());
|
||||||
|
|||||||
Reference in New Issue
Block a user