def send_img_db(cur, user_id, campaign_id, img_urls, img_names, img_info): for url, img_name, img_info in zip(img_urls, img_names, img_info): db.insert_tb(cur, "images", user_id=user_id, campaign_id=campaign_id, img_url=gc.quote(url), img_name=gc.quote(img_name), img_info=gc.quote(img_info))
def password_option(cur, table, user_id, key, value): """ Will update password args: returns: message (string) """ if len(value) < 8 or len(value) > 16: return "Password must be between 8 and 16" value, salt = gc.hash_pass(value) db.update_tb(cur, table, "user_id", user_id, key, gc.quote(value)) db.update_tb(cur, table, "user_id", user_id, "salt", gc.quote(value)) return ""
def create_campaign(user_id, campaign_name, tag_ids, img_urls, img_names, img_infos): """ The main function for admin creation. args: all strings returns: results (dictionary) """ remote = False con, cur = gc.setup_db(remote) # check if table exists # if not db.exist_tb(cur, ": # return gc.results(con, cur, "0", "Table has not yet been created") duplicate = db.exist_items(cur, 'campaigns', campaign_name=gc.quote(campaign_name)) if duplicate: return gc.results(con, cur, "0", "Campaign already exists") if db.get_item(cur, "user_cred", "user_id", user_id, "usertype") == "influencer": return gc.results(con, cur, "0", "User is not a business owner.") setup_campaign(cur, user_id, campaign_name, tag_ids, img_urls, img_names, img_infos) return gc.results(con, cur, "1") # print(create_campaign(2, "Banana Clubs", [1], ["HTTP"], ["banana"], ["long and yellow"]))
def check_username_pass(cur, table, email, phone, password): for char in email: email = email.lower() if not char.isalpha() and char != "@" and char != ".": return "Email contains invalid characters." if not any(word in email for word in [".edu", ".com", ".net", ".org", ".gov" ]) and email.count("@") != 1: return "Email is not valid or incorrectly formated." duplicate = (db.exist_items(cur, table, email=gc.quote(email)) or db.exist_items(cur, table, phone=gc.quote(phone))) if duplicate: return "User account exists" if len(password) < 8 or len(password) > 16: return "Password must be between 8 and 16"
def other_option(cur, table, user_id, key, value): """ Will update all user generic cases args: returns: message (string) """ db.update_tb(cur, table, "user_id", user_id, key, gc.quote(value)) return ""
def username_option(cur, table, user_id, key, value): """ Will update email args: returns: message (string) """ if key == 'email': value = value.lower() for char in value: if not char.isalpha() and char != "@" and char != ".": return "Email contains invalid characters" if not any(word in value for word in [".edu", ".com", ".net", ".org", ".gov" ]) and value.count("@") != 1: return "Email is not valid or incorrectly formated." if db.exist_items(cur, table, key=gc.quote(value)): return "Username already exists" db.update_tb(cur, table, "user_id", user_id, key, gc.quote(value)) return ""
def about_option(cur, table, user_id, key, value): """ Will update about part of the user args: returns: message (string) """ if len(value) > 256: return "Sentence too long" db.check_profile_exist(user_id) db.update_tb(cur, table, "user_id", user_id, key, gc.quote(value)) return ""
def send_admin_db(cur, usertype, name, phone, email, password, salt, reg_date): """ Will create an account in the database args: all strings returns: none """ db.insert_tb(cur, "admin_cred", usertype=gc.quote(usertype), name=gc.quote(name), phone=gc.quote(phone), email=gc.quote(email), password=gc.quote(password), salt=gc.quote(salt), reg_date=gc.quote(reg_date))
def approve_user(user_id, status): """ Will approve user args: user_id (int) returns: dictionary """ remote = False con, cur = gc.setup_db(remote) # check related tables exist if not gc.check_tb_relations(cur, "user"): return gc.results(con, cur, "0", "Necessary tables have not yet been created") db.del_row(cur, "approval_queue", "queued_id", int(user_id)) db.update_tb(cur, "user_cred", "user_id", user_id, "status", gc.quote(status)) return gc.results(con, cur, "1") # print(update("user", "1", "name", "Mr.banana"))
def send_camp_db(cur, user_id, campaign_name, tag_ids, create_date, rating, review, reviewer): """ Will create an account in the database args: all strings returns: none """ db.insert_tb(cur, "campaigns", user_id=user_id, campaign_name=gc.quote(campaign_name), tag_ids=gc.quote(tag_ids), create_date=gc.quote(create_date), rating=gc.quote(rating), review=gc.quote(review), reviewer=gc.quote(reviewer))
def send_user_db(cur, status, usertype, comp_name, name, borough, state, phone, email, password, salt, reg_date): """ Will create an account in the database args: all strings returns: none """ db.insert_tb(cur, "user_cred", status=gc.quote(status), usertype=gc.quote(usertype), comp_name=gc.quote(comp_name), name=gc.quote(name), borough=gc.quote(borough), state=gc.quote(state), phone=gc.quote(phone), email=gc.quote(email), password=gc.quote(password), salt=gc.quote(salt), reg_date=gc.quote(reg_date))