def set_leader(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('leader_id', None) is None): return obj2json(RetModel(70, dict_err_code[70], {})) if (False == db_is_user_exists(request.form["leader_id"])): return obj2json(RetModel(71, dict_err_code[71], {})) if request.form["uid"] == request.form["leader_id"]: return obj2json(RetModel(75, dict_err_code[75], {})) #check if my member lstUser = db_get_member_list(request.form['uid']) for user in lstUser: if request.form["uid"] == str(user["leader_uid"]): return obj2json(RetModel(74, dict_err_code[74], {})) if (False == db_set_user_leader(request.form['uid'], request.form["leader_id"])): return obj2json(RetModel(1000, dict_err_code[1000], {})) return obj2json(RetModel(0, dict_err_code[0], {}))
def get_password(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('phone', None) is None): return obj2json(RetModel(22, dict_err_code[22], {})) if (db_send_password(request.form['phone']) == True): return obj2json(RetModel(0, dict_err_code[0], {})) else: return obj2json(RetModel(1000, dict_err_code[1000], {}))
def query_users(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) lstUser = db_query_users() return obj2json(RetModel(0, dict_err_code[0], lstUser))
def delete_customer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21], {})) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) szRet = obj2json(RetModel(1024, dict_err_code[1024], {})) return szRet
def add_customer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(31, dict_err_code[31], {})) if (request.form.get('name', None) is None): return obj2json(RetModel(32, dict_err_code[32], {})) if (request.form.get('address', None) is None): return obj2json(RetModel(33, dict_err_code[33], {})) if (request.form.get('longitude', None) is None): return obj2json(RetModel(34, dict_err_code[34], {})) if (request.form.get('latitude', None) is None): return obj2json(RetModel(35, dict_err_code[35], {})) customer = Customer() customer.id = request.form['id'] customer.uid = request.form['uid'] customer.name = request.form['name'] customer.group_name = request.form.get('group_name', '') customer.spell = request.form.get('spell', '') customer.address = request.form['address'] customer.longitude = request.form['longitude'] customer.latitude = request.form['latitude'] customer.boss = request.form.get('boss', '') customer.phone = request.form.get('phone', '') customer.email = request.form.get('email', '') customer.description = request.form.get('description', '') customer.update_date = request.form.get('update_date', int(time.time())) if (True == insert_customer(request.form['uid'], customer)): szRet = obj2json(RetModel(0, dict_err_code[0], {})) else: szRet = obj2json(RetModel(1000, dict_err_code[1000], {})) return szRet
def get_group_list(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form.get('uid', ''), request.form.get('token', ''))): return obj2json(RetModel(21, dict_err_code[21], {})) lstGroup = select_group_list(request.form['uid'], request.form.get('type', '0')) szRet = obj2json(RetModel(0, dict_err_code[0], lstGroup)) return szRet
def get_user_profile(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('member_uid', None) is not None): #get profile for my member userProfile = db_query_user_profile(request.form['member_uid']) if (userProfile is None): return obj2json(RetModel(1000, dict_err_code[1000], {})) else: return obj2json(RetModel(0, dict_err_code[0], userProfile)) else: #get profile for myself userProfile = db_query_user_profile(request.form['uid']) if (userProfile is None): return obj2json(RetModel(1000, dict_err_code[1000], {})) else: return obj2json(RetModel(0, dict_err_code[0], userProfile))
def add_group(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form.get('uid', ''), request.form.get('token', ''))): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('group_name', None) is None or len(request.form.get('group_name', '')) <= 0): return obj2json(RetModel(60, dict_err_code[60], {})) if (request.form.get('update_date', None) is None or len(request.form.get('update_date', '')) <= 0): return obj2json(RetModel(61, dict_err_code[61], {})) if (insert_group(request.form['uid'], request.form['group_name'], request.form['update_date'])): return obj2json(RetModel(0, dict_err_code[0], {})) else: return obj2json(RetModel(1024, dict_err_code[1024], {}))
def get_posts(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('limit', None) is None or request.form.get('offset', None) is None): return obj2json(RetModel(46, dict_err_code[46], {})) if (False == request.form['limit'].isdigit() or False == request.form['offset'].isdigit()): return obj2json(RetModel(46, dict_err_code[46], {})) if (request.form.get('member_uid', None) is not None): lstNotes = select_note_for_member(request.form['member_uid'], request.form['limit'], request.form['offset']) szRet = obj2json(RetModel(0, dict_err_code[0], lstNotes)) return szRet else: lstNotes = db_query_posts_public_to_me(request.form['uid'], request.form['limit'], request.form['offset']) szRet = obj2json(RetModel(0, dict_err_code[0], lstNotes)) return szRet
def login(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('user_name', None) is None or request.form.get('password', None) is None or request.form.get("verify_code", None) is None): return obj2json(RetModel(20, dict_err_code[20])) user = user_login(request.form['user_name'], request.form['password'], request.form["verify_code"]) szRet = "" if (user == None): szRet = obj2json(RetModel(1, "user_name or password is incorrect", {})) else: retModel = RetModel(0, "success", user) szRet = obj2json(retModel) return szRet
def get_user_customer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) lstRet = [] if (request.form.get('member_uid', None) is not None): #get profile for my member lstRet = select_customer_list(request.form['member_uid'], '0') else: #get profile for myself lstRet = select_customer_list(request.form['uid'], '0') return obj2json(RetModel(0, dict_err_code[0], lstRet))
def get_customer_list(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('member_uid', None) is not None): lstCustomer = select_customer_list(request.form['member_uid'], request.form.get('type', '0')) szRet = obj2json(RetModel(0, dict_err_code[0], lstCustomer)) return szRet else: lstCustomer = select_customer_list(request.form['uid'], request.form.get('type', '0')) szRet = obj2json(RetModel(0, dict_err_code[0], lstCustomer)) return szRet
def delete_note(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(41, dict_err_code[41])) if (remove_note(request.form['uid'], request.form['id'])): return obj2json(RetModel(0, dict_err_code[0], {})) else: return obj2json(RetModel(1000, dict_err_code[1000], {}))
def update_user_info(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('avatar', None) is None): return obj2json(RetModel(72, dict_err_code[72])) if (request.form.get('show_name', None) is None): return obj2json(RetModel(73, dict_err_code[73])) if (db_update_user_info(request.form["uid"], request.form["avatar"], request.form["show_name"])): return obj2json(RetModel(0, dict_err_code[0], {})) else: return obj2json(RetModel(1000, dict_err_code[1000], {}))
def get_notes_list(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('limit', None) is None or request.form.get('offset', None) is None): return obj2json(RetModel(46, dict_err_code[46], {})) if (False == request.form['limit'].isdigit() or False == request.form['offset'].isdigit()): return obj2json(RetModel(46, dict_err_code[46], {})) if (request.form.get('member_uid', None) is not None): lstNoteId = select_note_list(request.form['member_uid'], int(request.form['limit']), int(request.form['offset']), request.form.get('type', '0')) szRet = obj2json(RetModel(0, dict_err_code[0], lstNoteId)) return szRet else: lstNoteId = select_note_list(request.form['uid'], request.form['limit'], request.form['offset'], request.form.get('type', '0')) szRet = obj2json(RetModel(0, dict_err_code[0], lstNoteId)) return szRet
def job_transfer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('uid_src', None) is None): return obj2json(RetModel(80, dict_err_code[80], {})) if (request.form.get('uid_dst', None) is None): return obj2json(RetModel(81, dict_err_code[81], {})) #thread.start_new_thread(db_transfer_user_data, (request.form["uid_src"], request.form["uid_dst"])) db_transfer_user_data(request.form["uid_src"], request.form["uid_dst"]) return obj2json(RetModel(0, dict_err_code[0], {}))
def get_note(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(41, dict_err_code[41], {})) note = select_note(request.form['uid'], request.form['id']) szRet = "" if (note is None): szRet = obj2json(RetModel(40, dict_err_code[40], {})) else: szRet = obj2json(RetModel(0, dict_err_code[0], note)) return szRet
def get_customer(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(31, dict_err_code[31], {})) customer = select_customer(request.form['uid'], request.form['id']) szRet = "" if (customer is None): szRet = obj2json(RetModel(30, dict_err_code[30], {})) else: szRet = obj2json(RetModel(0, dict_err_code[0], customer)) return szRet
def repost(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) if (request.form.get('uid', None) is None or request.form.get('token', None) is None): return obj2json(RetModel(21, dict_err_code[21])) if (False == verify_user_token(request.form['uid'], request.form['token'])): return obj2json(RetModel(21, dict_err_code[21], {})) if (request.form.get('id', None) is None): return obj2json(RetModel(41, dict_err_code[41], {})) if (request.form.get('address', None) is None): return obj2json(RetModel(43, dict_err_code[43], {})) if (request.form.get('longitude', None) is None): return obj2json(RetModel(44, dict_err_code[44], {})) if (request.form.get('latitude', None) is None): return obj2json(RetModel(45, dict_err_code[45], {})) if (request.form.get('customer_id', None) is None): return obj2json(RetModel(31, dict_err_code[31], {})) if (request.form.get('note', None) is None): return obj2json(RetModel(40, dict_err_code[40], {})) if (request.form.get('repost_from', None) is None): return obj2json(RetModel(47, dict_err_code[47], {})) note = {} note["id"] = request.form['id'] note["uid"] = request.form['uid'] note["date"] = request.form.get('date', int(time.time())) note["update_date"] = request.form.get('update_date', int(time.time())) note["customer_id"] = request.form['customer_id'] note["address"] = request.form['address'] note["longitude"] = request.form['longitude'] note["latitude"] = request.form['latitude'] note["note"] = request.form['note'] note["thumbnail"] = request.form.get('thumbnail', '') note["pic"] = request.form.get('pic', '') note["repost_from"] = request.form.get('repost_from', '0') if (True == db_repost_note(request.form['uid'], note)): szRet = obj2json(RetModel(0, dict_err_code[0], {})) else: szRet = obj2json(RetModel(1000, dict_err_code[1000], {})) return szRet
def upload_file(): if request.method == 'GET': return obj2json(RetModel(1, dict_err_code[1], {})) dictFiles = {} if 'pic1' not in request.files: return obj2json(RetModel(11, dict_err_code[11], {})) file1 = request.files['pic1'] if file1 and allowed_file(file1.filename): filename = secure_filename(file1.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file1.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic1"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic2' in request.files: file2 = request.files['pic2'] if file2 and allowed_file(file2.filename): filename = secure_filename(file2.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file2.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic2"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic3' in request.files: file3 = request.files['pic3'] if file3 and allowed_file(file3.filename): filename = secure_filename(file3.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file3.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic3"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic4' in request.files: file4 = request.files['pic4'] if file4 and allowed_file(file4.filename): filename = secure_filename(file4.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file4.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic4"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic5' in request.files: file5 = request.files['pic5'] if file5 and allowed_file(file5.filename): filename = secure_filename(file5.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file5.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic5"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic6' in request.files: file6 = request.files['pic6'] if file6 and allowed_file(file6.filename): filename = secure_filename(file6.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file6.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic6"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic7' in request.files: file7 = request.files['pic7'] if file7 and allowed_file(file7.filename): filename = secure_filename(file7.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file7.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic7"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic8' in request.files: file8 = request.files['pic8'] if file8 and allowed_file(file8.filename): filename = secure_filename(file8.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file8.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic8"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) if 'pic9' in request.files: file9 = request.files['pic9'] if file9 and allowed_file(file9.filename): filename = secure_filename(file9.filename) savedFileName = str(uuid.uuid4()) + get_file_ext(filename) file9.save(os.path.join(UPLOAD_FOLDER, savedFileName)) dictFiles["pic9"] = savedFileName else: return obj2json(RetModel(10, dict_err_code[10], {})) return obj2json(RetModel(0, dict_err_code[0], dictFiles))