From 9f7628b39445174010ba50d2d3428d84c8f5d3c7 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sat, 20 May 2023 19:01:03 -0400 Subject: [PATCH] Generating username --- wrenchboard/src/include/common_tool.h | 1 + wrenchboard/src/shared_tool/common_tool.cc | 29 +++++++++++++++++++++- wrenchboard/src/shared_tool/family_acc.cc | 9 +++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/wrenchboard/src/include/common_tool.h b/wrenchboard/src/include/common_tool.h index 4ddf9bae..87101084 100644 --- a/wrenchboard/src/include/common_tool.h +++ b/wrenchboard/src/include/common_tool.h @@ -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 diff --git a/wrenchboard/src/shared_tool/common_tool.cc b/wrenchboard/src/shared_tool/common_tool.cc index ff3182f7..4c57b8b5 100644 --- a/wrenchboard/src/shared_tool/common_tool.cc +++ b/wrenchboard/src/shared_tool/common_tool.cc @@ -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 ); +} \ No newline at end of file diff --git a/wrenchboard/src/shared_tool/family_acc.cc b/wrenchboard/src/shared_tool/family_acc.cc index 28262b51..5359f54d 100644 --- a/wrenchboard/src/shared_tool/family_acc.cc +++ b/wrenchboard/src/shared_tool/family_acc.cc @@ -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