diff --git a/wrenchboard/src/shared_tool/account_mngt.cc b/wrenchboard/src/shared_tool/account_mngt.cc index efffc74b..3396bf8f 100644 --- a/wrenchboard/src/shared_tool/account_mngt.cc +++ b/wrenchboard/src/shared_tool/account_mngt.cc @@ -700,119 +700,101 @@ long CreateWrenchBoardAccountPending(CVars in, CVars &out) { long ret = PHP_API_BAD_PARAM; out = in; - /* - CREATE TABLE members_pending ( -id SERIAL, - username VARCHAR(50) UNIQUE NOT NULL, - firstname VARCHAR(50), - lastname VARCHAR(50), - email VARCHAR(50), - phone VARCHAR(25), -password VARCHAR(100), -status integer DEFAULT 1, -added timestamp without time zone DEFAULT now(), - verify_link VARCHAR(100), -terms integer DEFAULT 0, -news integer DEFAULT 0, - expire timestamp without time zone DEFAULT now() +'30 days' - ); - ALTER TABLE ONLY members_pending -ADD CONSTRAINT members_pending_id_key UNIQUE (id); - */ - - if ( load_db_record(out, "SELECT id FROM members_pending WHERE LOWER(username)=LOWER('%s')",in["username"].c_str()) > 0 ){ - out["password"]="REMOVED"; - out["acc"]="DULPICATE"; - return -1; - } - if ( load_db_record(out, "SELECT uid FROM members WHERE LOWER(username)=LOWER('%s')",in["username"].c_str())> 0 ){ - out["password"]="REMOVED"; - out["acc"]="DULPICATE"; - return -1; - } - - REQ_STRING(in, "username", 5, 49, "(.*)"); - REQ_STRING(in, "firstname", 2, 49, "(.*)"); - REQ_STRING(in, "lastname", 2, 49, "(.*)"); - REQ_STRING(in, "email", 5, 49, "(.*)"); - OPTIONAL(in, "phone") REQ_STRING(in, "phone", 3, 15, "(.*)"); - OPTIONAL(in, "loc") REQ_STRING(in, "loc", 3, 15, "(.*)"); - long news = REQ_LONG(in, "news", 1, -1); - long terms = REQ_LONG(in, "terms", 1, -1); - REQ_STRING(in, "password", 5, 25, "(.*)"); - OPTIONAL(in, "country") REQ_STRING(in, "country", 1, 3, "(.*)"); - //const char * loc = getenv('REMOTE_ADDR'); - //in["loc"] = loc; - OPTIONAL(in, "mobile") REQ_STRING(in, "mobile", 3, 15, "(.*)"); + try { - int r1, r2, r3,signup_random; - char verify_link[100]; - srand(time(NULL)); - r1 = abs(rand()*100); - srand(time(NULL)); - r2 = abs(rand() * r1); - srand(time(NULL)); - r3 = abs(rand() * r2); - srand(time(NULL)); - - - signup_random = abs(rand()*0.009); - - - sprintf(verify_link, "WRENCHB-%09lu-%08lu-%08lu", r1, r2, r3); - - - CVars x; - x["username"] = in["username"]; - x["username"].set_valid(true); - x["firstname"] = in["firstname"]; - x["firstname"].set_valid(true); - x["lastname"] = in["lastname"]; - x["lastname"].set_valid(true); - x["email"] = in["email"]; - x["email"].set_valid(true); - x["phone"] = in["phone"]; - x["phone"].set_valid(true); - x["country"] = in["country"]; - x["country"].set_valid(true); - - if (in["loc"].length() > 0) x["loc"] = in["loc"]; - x["loc"].set_valid(true); - x["verify_link"] = verify_link; - x["verify_link"].set_valid(true); - - x["news"] = in["news"]; - x["news"].set_valid(true); - x["terms"] = in["terms"]; - x["terms"].set_valid(true); - - ret = insert_db_record(DBS_VALID, "members_pending", "members_pending_id_seq", x); - - if (ret > 0) { - pgsql_query("UPDATE members_pending SET password = md5('%s'),signup_random=%lu WHERE id = %lu", in["password"].c_str(),signup_random/1000, ret); - pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s'", x["email"].c_str()); - - load_db_record(out, "SELECT *,id AS pending_id FROM members_pending WHERE id=%lu LIMIT 1", ret); - } - - - - - if (ret > 0) { - out["pending_id"] = ret; - out["pending_id"].set_valid(true); - x["pending_id"] = ret; - x["pending_id"].set_valid(true); - - if (in["mobile"] != "" && in["mobile"] == "MOBILE") { - //ALTER TABLE members_pending ADD signup_random INT; - x["mobile_email"] = "100"; x["mobile_email"].set_valid( true ); - AccountPendingMail(x); - } else { - AccountPendingMail(x); + if ( load_db_record(out, "SELECT id FROM members_pending WHERE LOWER(username)=LOWER('%s')",in["username"].c_str()) > 0 ){ + out["password"]="REMOVED"; + out["acc"]="DULPICATE"; + return PHP_API_BAD_PARAM; } - SignupPendingAlertMailfile(x); - } + if ( load_db_record(out, "SELECT uid FROM members WHERE LOWER(username)=LOWER('%s')",in["username"].c_str())> 0 ){ + out["password"]="REMOVED"; + out["acc"]="DULPICATE"; + return PHP_API_BAD_PARAM; + } + + + + REQ_STRING(in, "username", 5, 49, "(.*)"); + REQ_STRING(in, "firstname", 2, 49, "(.*)"); + REQ_STRING(in, "lastname", 2, 49, "(.*)"); + REQ_STRING(in, "email", 5, 49, "(.*)"); + OPTIONAL(in, "phone") REQ_STRING(in, "phone", 3, 15, "(.*)"); + OPTIONAL(in, "loc") REQ_STRING(in, "loc", 3, 15, "(.*)"); + long news = REQ_LONG(in, "news", 1, -1); + long terms = REQ_LONG(in, "terms", 1, -1); + REQ_STRING(in, "password", 5, 25, "(.*)"); + OPTIONAL(in, "country") REQ_STRING(in, "country", 1, 3, "(.*)"); + //const char * loc = getenv('REMOTE_ADDR'); + //in["loc"] = loc; + OPTIONAL(in, "mobile") REQ_STRING(in, "mobile", 3, 15, "(.*)"); + + int r1, r2, r3,signup_random; + char verify_link[100]; + srand(time(NULL)); + r1 = abs(rand()*100); + srand(time(NULL)); + r2 = abs(rand() * r1); + srand(time(NULL)); + r3 = abs(rand() * r2); + srand(time(NULL)); + + signup_random = abs(rand()*0.009); + sprintf(verify_link, "WRENCHB-%09lu-%08lu-%08lu", r1, r2, r3); + + CVars x; + x["username"] = in["username"]; + x["username"].set_valid(true); + x["firstname"] = in["firstname"]; + x["firstname"].set_valid(true); + x["lastname"] = in["lastname"]; + x["lastname"].set_valid(true); + x["email"] = in["email"]; + x["email"].set_valid(true); + x["phone"] = in["phone"]; + x["phone"].set_valid(true); + x["country"] = in["country"]; + x["country"].set_valid(true); + + if (in["loc"].length() > 0) x["loc"] = in["loc"]; + x["loc"].set_valid(true); + x["verify_link"] = verify_link; + x["verify_link"].set_valid(true); + + x["news"] = in["news"]; + x["news"].set_valid(true); + x["terms"] = in["terms"]; + x["terms"].set_valid(true); + + ret = insert_db_record(DBS_VALID, "members_pending", "members_pending_id_seq", x); + + if (ret > 0) { + pgsql_query("UPDATE members_pending SET password = md5('%s'),signup_random=%lu WHERE id = %lu", in["password"].c_str(),signup_random/1000, ret); + pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s'", x["email"].c_str()); + + load_db_record(out, "SELECT *,id AS pending_id FROM members_pending WHERE id=%lu LIMIT 1", ret); + } + + if (ret > 0) { + out["pending_id"] = ret; + out["pending_id"].set_valid(true); + x["pending_id"] = ret; + x["pending_id"].set_valid(true); + + if (in["mobile"] != "" && in["mobile"] == "MOBILE") { + //ALTER TABLE members_pending ADD signup_random INT; + x["mobile_email"] = "100"; x["mobile_email"].set_valid( true ); + AccountPendingMail(x); + } else { + AccountPendingMail(x); + } + SignupPendingAlertMailfile(x); + } + + + } catch (bad_parameter) { + out["status"] = "ERROR"; + } return ret; }