Generating username
This commit is contained in:
@@ -9,6 +9,7 @@ void GenerateInnerConfirmationSeed( char * number, int sz, int seed );
|
||||
long GetMemberAccountLink(long member_id, CVars &out);
|
||||
void GetOfferCode( unsigned long offer_id, char * number, int sz );
|
||||
void Confirmation( unsigned long payment_id, char * number, int sz );
|
||||
void SetFamilyUsername( unsigned long family_id, char * number, int sz );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void GenerateConfirmation( char * number, int sz )
|
||||
|
||||
void GenerateConfirmationSeed( char * number, int sz, int seed )
|
||||
{
|
||||
char chars[] = "WRB01234WRB56789WRB";
|
||||
char chars[] = "WRB01234WRB56789WRBXQFDTYP";
|
||||
int n = sizeof(chars);
|
||||
int i;
|
||||
/*
|
||||
@@ -99,3 +99,30 @@ void GetOfferCode( unsigned long offer_id, char * number, int sz )
|
||||
pgsql_exec("COMMIT" ); // Unlock table 'data'
|
||||
strsafecpy( number, offer_code, sz );
|
||||
}
|
||||
|
||||
|
||||
void SetFamilyUsername( unsigned long family_id, char * number, int sz )
|
||||
{
|
||||
SQLINTEGER rows;
|
||||
char family_username[14];
|
||||
|
||||
// Lock table to prevent generation of two identical username
|
||||
pgsql_exec("BEGIN; LOCK TABLE members_family;" );
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
GenerateConfirmationSeed( family_username, sizeof(family_username), i++ );
|
||||
|
||||
//st.CloseCursor();
|
||||
rows = 0;
|
||||
const PGresult *res = pgsql_query("SELECT id FROM members_family WHERE username='%s'", family_username );
|
||||
if (res!=NULL )
|
||||
{
|
||||
rows = pgsql_num_rows(res);
|
||||
}
|
||||
} while ( rows>0 && i<100 );
|
||||
|
||||
pgsql_exec("UPDATE members_family SET username='%s' WHERE id=%lu", family_username, family_id );
|
||||
pgsql_exec("COMMIT" ); // Unlock table 'data'
|
||||
strsafecpy( number, family_username, sz );
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "mobile.h"
|
||||
#include "jobs_manager.h"
|
||||
#include "family_acc.h"
|
||||
#include "common_tool.h"
|
||||
|
||||
long WrenchFamilyList(CVars in, CVars &out);
|
||||
long WrenchFamilyAdd(CVars in, CVars &out);
|
||||
@@ -215,13 +216,17 @@ return ret;
|
||||
}
|
||||
|
||||
long WrenchFamilyInitializeAccount(CVars in, CVars &out){
|
||||
logfmt(logINFO, "WrenchFamilyInitializeAccount()");
|
||||
|
||||
logfmt(logINFO, "WrenchFamilyInitializeAccount()");
|
||||
|
||||
char username[15] = "";
|
||||
GetOfferCode(in["family_id"].Long(), username, sizeof (username));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
#define WRENCHBOARD_FAMILY_LIST 22010
|
||||
|
||||
Reference in New Issue
Block a user