def validate_user_save(username, password, age, sex, telephone, department, \ birthday, hobby, email, detail): username = username.strip() password = password.strip() if username == '': return False, 'username is empty' if len(username) > 25: return False, 'username is lt 25' if password == '': return False, 'password is empty' if len(password) > 25 or len(password) < 6: return False, 'password is between 6 and 25' if not str(age).isdigit() or int(age) < 1 or int(age) > 120: return False, 'age is 1 and 120 integer' _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_USER_SAVE, (username,)) if _rt: return False, 'username is used by others' if int(sex) != 0 and int(sex) != 1: return False, 'sex is between 0 and 1' if not str(telephone).isdigit() or len(telephone) != 11: return False, 'telephone is 11 digit number ' if birthday == '': return False, 'birthday is empty' if hobby == '': return False, 'hobby is empty' if email == '': return False, 'email is empty' if detail == '': return False, 'detail is empty' if not str(department).isdigit() or int(department) < 1 or int(department) > 3: return False, 'department is a number 1-3' return True, ''
def validate_user_modify(username, age, uid): username = username.strip() if not get_user_by_id(uid): return False, 'user is not found' if username == '': return False, 'username is empty' if len(username) > 25: return False, 'username is lt 25' if not str(age).isdigit() or int(age) < 1 or int(age) > 120: return False, 'age is 1 and 120 integer' _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_USER_MODIFY, (uid, username)) if _rt: return False, 'username is used by others' return True, ''
def validate_user_save(username, password, age): username = username.strip() password = password.strip() if username == '': return False, 'username is empty' if len(username) > 25: return False, 'username is lt 25' if password == '': return False, 'password is empty' if len(password) > 25 or len(password) < 6: return False, 'password is between 6 and 25' if not str(age).isdigit() or int(age) < 1 or int(age) > 120: return False, 'age is 1 and 120 integer' _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_ROOM_SAVE, (username,)) if _rt: return False, 'username is used by others' return True, ''
def validate_room_save(roomname, addr, ip_ranges): roomname = roomname.strip() addr = addr.strip() ip_ranges = ip_ranges.strip() print ip_ranges if roomname == '': return False, 'roomname is empty' if len(roomname) > 64: return False, 'roomname is gt 64' if addr == '': return False, 'addr is empty' if len(addr) > 128: return False, 'addr is gt 128' if not IPChecker_re(ip_ranges): return False, 'ip_ranges is not ip_address type' _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_ROOM_SAVE, (roomname,)) if _rt: return False, 'roomname is used by others' return True, ''
def validate_room_modify(rid, roomname, addr, ip_ranges): roomname = roomname.strip() addr = addr.strip() ip_ranges = ip_ranges.strip() if not get_room_by_id(rid): return False, 'room is not found' if roomname == '': return False, 'roomname is empty' if len(roomname) > 64: return False, 'roomname is gt 64' if addr == '': return False, 'addr is empty' if len(addr) > 128: return False, 'addr is gt 128' if not IPChecker_re(ip_ranges): return False, 'ip_ranges is not ip_address type' _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_ROOM_MODIFY, (rid, roomname), fetch=False) if _rt: return False, 'roomname is used by others' return True, ''
def validate_login(username, password): _count, _rt = dbutils.execute_all_sql(SQL_VALIDATE_LOGIN, (username, password)) # rt = None # if record is not None: # rt = {'id': record[0], 'name': record[1]} return None if _rt is None else dict(zip(SQL_VALIDATE_LOGIN_COLUMNS, _rt[0]))
def get_user_by_id(uid): _count, _rt = dbutils.execute_all_sql(SQL_USER_BY_ID, (uid,)) print _rt return {} if _rt is None else dict(zip(SQL_USER_BY_ID_COLUMNS, _rt[0]))
def get_users(): _count, _rt_list = dbutils.execute_all_sql(SQL_USER_LIST) return [dict(zip(SQL_USER_LIST_COLUMNS, x)) for x in _rt_list]
def room_modify(rid, roomname, addr, ip_ranges): _count, _rt = dbutils.execute_all_sql(SQL_ROOM_MODIFY, (roomname, addr, ip_ranges, rid), fetch=False) print _count, _rt return _count # update 可能没修改的话返回0,修改成功返回的是1所以都要返回一个值 不能用!=0
def room_delete(rid): _count, _rt = dbutils.execute_all_sql(SQL_ROOM_DELETE_BY_ID, (rid,), fetch=False) return _count != 0
def get_room_by_id(rid): _count, _rt = dbutils.execute_all_sql(SQL_ROOM_BY_ID, (rid,)) print _rt return {} if _rt is None else dict(zip(SQL_ROOM_BY_ID_COLUMNS, _rt[0]))
def room_save(roomname, addr, ip_ranges): _count, _rt = dbutils.execute_all_sql(SQL_ROOM_SAVE, (roomname, addr, ip_ranges), fetch=False) return _count != 0
def get_rooms(): _count, _rt_list = dbutils.execute_all_sql(SQL_ROOM_LIST) return [dict(zip(SQL_ROOM_LIST_COLUMNS, li)) for li in _rt_list]
def user_modify(username, age, uid, sex, telephone, department, birthday, hobby, email, detail): _count, _rt = dbutils.execute_all_sql(SQL_USER_MODIFY, (username, age, telephone, sex, department, \ birthday, hobby, email, detail, uid), fetch=False) print _count, _rt return _count # update 可能没修改的话返回0,修改的是1所以都要返回一个值 不能用!=0
def user_delete(uid): _count, _rt = dbutils.execute_all_sql(SQL_USER_DELETE_BY_ID, (uid,), fetch=False) return _count != 0 # 当删除成功时_count不等于0,返回_count;插入失败返回的则是默认值None
def user_save(username, password, age, telephone, sex, department, birthday, hobby, email, detail): _count, _rt = dbutils.execute_all_sql(SQL_USER_SAVE, (username, password, age, telephone, sex, \ department, birthday, hobby, email, detail), fetch=False) print _count return _count != 0 # 当插入成功时_count不等于0,返回_count;插入失败返回的则是默认值None