def regist_info_rc(p_ob): for items_feature in p_ob.feature_array: for items_record in items_feature.record_array: if items_feature.apellation == "用户名": rule_error = my_proces_text.check_username_rule( items_record.num) # 调用my_proces_text模块的用户名规则检查方法 if rule_error == True: sql_cmd = "SELECT USER_APELLATION FROM User WHERE USER_APELLATION = '%s'" % items_record.num # 查询数据库 result = SQL('Web_Shop_User_DB', sql_cmd) # 以元组形式返回匹配到的结果。 if len(result) != 0: rule_error = my_proces_text.color( "用户名已存在!", 'red', 'l') return rule_error else: rule_error = my_proces_text.color(rule_error, 'red', 'l') return rule_error elif items_feature.apellation == "密码": rule_error = my_proces_text.check_password_rule( items_record.num, 2) # 调用my_proces_text模块的密码规则检查方法 if rule_error != True: rule_error = my_proces_text.color(rule_error, 'red', 'l') return rule_error elif items_feature.apellation == "电子邮箱": rule_error = my_proces_text.check_email_rule( items_record.num) # 调用my_proces_text模块的电子邮箱规则检查方法 if rule_error != True: rule_error = my_proces_text.color(rule_error, 'red', 'l') return rule_error rule_error = True return rule_error
def select(p_db_name, p_table, p_key_1, p_value, p_key_2): # 取p_key_1 = p_value 的 p_key_2 的值 db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name, charset='utf8') cursor = db.cursor() # sql = "SELECT %s FROM %s" % (p_key, p_table) sql = "SELECT %s FROM %s WHERE %s = '%s'" % ( p_key_2, p_table, p_key_1, p_value) # 取USERNAME = test_2 的 PASSWORD try: cursor.execute(sql) args = cursor.fetchall() for i in args: print i[0] result = p_table temp = "数据表:%s 读取成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: result = False temp = "数据表:%s 读取失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def account_regist(): ar_flag_1 = 1 while (ar_flag_1 != 'q'): regist_page() #显示注册页面 ar_flag_1 = raw_input("是否开始注册?\n(y/n): ") if ar_flag_1 == 'y': ob_user = my_interactive_fill_info.fill_regist_info( ) #调用my_interactive_fill_info模块的注册账户方法,返回构建好基础数据的用户对象。 my_interactive_fill_info.display_regist_info( ob_user) #调用my_interactive_fill_info模块的显示注册信息方法。 my_interactive_validate.text_validate( ) #调用my_interactive_validate模块的文本验证方法 ar_flag_2 = raw_input("是否提交?\n(y/n): ") if ar_flag_2 == 'y': result = my_API_mysql.regist_info_rc( ob_user) #调用my_API_mysql模块的规则检查方法,返回错误信息字符串,无措返回True。 if result == True: my_API_mysql.user_info_insert_mysql( my_API_mysql.DB_DB_NAME, ob_user) #调用my_API_mysql模块的数据库插入方法,上传信息到数据库。 print my_proces_text.color("注册成功!密码以加密!写入MySQL数据库!", 'green', 'l') ar_flag_1 = 'q' else: print result elif ar_flag_1 == 'n': ar_flag_1 = 'q' else: print '退出注册页面!'
def fill_regist_info(): for items in BASIC_FEATURE_ORDER: if items == "用户名": tmp_var = raw_input("请输入%s: " % items) ob_user = my_Class_User.User(tmp_var, "vip") #构建用户 ob_user.create_feature(items, FEATURE_ARRAY_D.get(items)) #构建用户属性 ob_user.feature.create_record('str', tmp_var) #构建用户属性记载 elif items == "密码": while (True): tmp_var_1 = raw_input("请输入%s: " % items) tmp_var_2 = raw_input("请再次输入%s: " % items) if tmp_var_1 == tmp_var_2: break else: print my_proces_text.color("密码不一致,请重新输入!", 'red', 'l') ob_user.create_feature(items, FEATURE_ARRAY_D.get(items)) #构建用户属性 ob_user.feature.create_record('str', tmp_var_1) #构建用户属性记载 else: tmp_var = raw_input("请输入%s: " % items) ob_user.create_feature(items, FEATURE_ARRAY_D.get(items)) #构建用户属性 ob_user.feature.create_record('str', tmp_var) #构建用户属性记载 return ob_user #返回用户对象
def SQL(p_db_name, p_str): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name, charset='utf8') cursor = db.cursor() sql_cmd = p_str.split(' ')[0] try: cursor.execute(p_str) db.commit() if sql_cmd == 'SELECT': result = cursor.fetchall() # result = result.decode('utf-8').encode('gbk') else: result = True temp = "%s:成功!" % sql_cmd print my_proces_text.color(temp, 'green', 'l') except: db.rollback() result = False temp = "%s:失败!" % sql_cmd print my_proces_text.color(temp, 'red', 'l') db.close() return result
def account_regist(): result = None ar_flag_1 = 1 while (ar_flag_1 != 'q'): regist_page() #显示注册页面 ar_flag_1 = raw_input("是否开始注册?\n(y/n): ") if ar_flag_1 == 'y': ob_user = my_interactive_fill_info.fill_regist_info( my_API_mysql.DB_NAME ) #调用my_interactive_fill_info模块的注册账户方法,内置规则检测,返回构建好基础数据的用户对象。 my_interactive_fill_info.display_regist_info( ob_user) #调用my_interactive_fill_info模块的显示注册信息方法。 result = my_interactive_validate.text_validate( ) #调用my_interactive_validate模块的文本验证方法 # ob_user.feature.update_record('str','12306') # ob_user.feature.update_record('str','88888') if result == True: my_API_mysql.user_info_insert_mysql( my_API_mysql.DB_NAME, ob_user) #调用my_API_mysql模块的数据库插入方法,上传信息到数据库。 print my_proces_text.color("注册成功!密码以加密!写入MySQL数据库!", 'green', 'l') result = ob_user #注册成功返回用户对象 ar_flag_1 = 'q' elif ar_flag_1 == 'n': ar_flag_1 = 'q' else: print '退出注册页面!' return result
def display_regist_info(p_ob): tmp_strng = '用户名: ' + p_ob.apellation print my_proces_text.color(tmp_strng, 'blue', 'l') for items_feature in p_ob.feature_array: for items_record in items_feature.record_array: if items_feature.apellation != "密码": tmp_strng = items_feature.apellation + ': ' + items_record.num print my_proces_text.color(tmp_strng, 'blue', 'l')
def text_validate(): while (True): text = __generate_text() print my_proces_text.color(text, 'black', 'l', 'white') var = raw_input('请输入验证码: ') if var == text: return True else: print my_proces_text.color('验证码错误请重新输入!', 'red', 'l')
def delete_table(p_db_name, p_table): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name) cursor = db.cursor() sql = "DROP TABLE %s" % p_table try: cursor.execute(sql) result = p_table temp = "数据表:%s 删除成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: result = False temp = "数据表:%s 删除失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def create_database(p_db_name): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD) cursor = db.cursor() sql = "CREATE DATABASE %s" % p_db_name try: cursor.execute(sql) result = p_db_name temp = "数据库:%s 创建成功!" % p_db_name print my_proces_text.color(temp, 'green', 'l') except: result = False temp = "数据库:%s 创建失败!" % p_db_name print my_proces_text.color(temp, 'red', 'l') db.close() return result
def create_table(p_db_name, p_table): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name) cursor = db.cursor() # sql = "CREATE TABLE %s (FIRST_NAME CHAR(20) NOT NULL,LAST_NAME CHAR(20),AGE INT,INCOME FLOAT)" % p_table sql = "CREATE TABLE %s (USERNAME CHAR(20),PASSWORD CHAR(20))" % p_table try: cursor.execute(sql) result = p_table temp = "数据表:%s 创建成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: result = False temp = "数据表:%s 创建失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def clear_table(p_db_name, p_table): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name) cursor = db.cursor() sql = "DELETE FROM %s" % p_table try: cursor.execute(sql) db.commit() result = p_table temp = "数据表:%s 记录清空成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: db.rollback() result = False temp = "数据表:%s 记录清空失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def register_user(): user_apellation = raw_input( my_proces_text.color('Plaes input User apellation:\n', 'green', 'l')) ob = User(user_apellation, 'vip') while (1): feature_apellation = raw_input( my_proces_text.color('Plaes input feature apellation:\n', 'blue', 'l')) num_apellation = raw_input( my_proces_text.color('Plaes input record apellation:\n', 'yellow', 'l')) num = raw_input(my_proces_text.color('Plaes input Vol:\n', 'red', 'l')) ob.create_feature(feature_apellation, 'personal', 'str') ob.feature.create_record(num_apellation, 'ing') ob.feature.num.create_num(num) ob.printf() tmp = raw_input( my_proces_text.color('Plaes check! y/n?\n', 'red', 'f')) if tmp == 'y': print 'Updata in my_API_mysql' ob.input_db() tmp = raw_input(my_proces_text.color('Qiut? y/n\n', 'red', 'l')) if tmp == 'y': break
def insert_table(p_db_name, p_table, p_value1, p_value2): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name, charset='utf8') cursor = db.cursor() sql = "INSERT INTO %s VALUES ('%s','%s')" % (p_table, p_value1, p_value2) # sql = "INSERT INTO %s(USERNAME,PASSWORD) VALUES ('%s','%s')" % (p_table, p_key, p_value) try: cursor.execute(sql) db.commit() result = p_table temp = "数据表:%s 插入记录成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: db.rollback() result = False temp = "数据表:%s 插入记录失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def fill_login_info(p_db_name): for items in LOGIN_FEATURE_ORDER: tmp_array = FEATURE_WORDBOOK.get(items) while (True): tmp_var = raw_input("请输入%s: " % items) if items == '用户名': result = my_Class_User.login_user( tmp_var, db_apellation=p_db_name) #检测规则和重名,并创建用户对象 if type(result) != str: ob_user = result break else: print my_proces_text.color(result, 'red', 'l') else: ob_user.create_feature(items, tmp_array[0]) result = ob_user.feature.create_record(tmp_array[1], tmp_var) if result != True: print my_proces_text.color(result, 'red', 'l') else: break return ob_user
def update_table(p_db_name, p_table, p_key, p_value): db = MySQLdb.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, p_db_name, charset='utf8') cursor = db.cursor() sql = "UPDATE %s SET PASSWORD = '******' WHERE %s = '%s'" % (p_table, p_key, p_value) # sql = "INSERT INTO %s(USERNAME,PASSWORD) VALUES ('%s','%s')" % (p_table, p_key, p_value) try: cursor.execute(sql) db.commit() result = p_table temp = "数据表:%s 更新成功!" % p_table print my_proces_text.color(temp, 'green', 'l') except: db.rollback() result = False temp = "数据表:%s 更新失败!" % p_table print my_proces_text.color(temp, 'red', 'l') db.close() return result
def account_login(): result = None al_flag_1 = 1 password_error = 0 while (al_flag_1 != 'q'): login_page() #显示登入页面 al_flag_1 = raw_input("是否开始登入?\n(y/n): ") if al_flag_1 == 'y': ob_user = my_interactive_fill_info.fill_login_info( my_API_mysql.DB_NAME) result = my_interactive_validate.text_validate( ) #调用my_interactive_validate模块的文本验证方法 if result == True: #对比密码是否正确 result = my_API_mysql.user_password_cmp_mysql( my_API_mysql.DB_NAME, ob_user) if result == True: #密码正确,检测锁定状态 result = my_API_mysql.user_locked_check( my_API_mysql.DB_NAME, ob_user, 3) if result == True: #没有被锁定,登入成功,退出循环并返回用户对象 print my_proces_text.color( '%s登入成功!' % ob_user.apellation, 'green', 'l') result = ob_user al_flag_1 = 'q' else: #账户以为锁定,返回带有剩余时间的错误信息 print my_proces_text.color(result, 'red', 'l') result = False else: #密码错误,记录错误次数,返回错误信息 result = my_API_mysql.user_password_wrong_proces( my_API_mysql.DB_NAME, ob_user, 3, 10) #错误上限为3次 ,锁定时间为10分钟 if type(result) == str: print my_proces_text.color(result, 'red', 'l') else: result = False elif al_flag_1 == 'n': al_flag_1 = 'q' else: print '退出登入页面!' return result
def login_page(): print my_proces_text.color(''' 账户登入! ''', 'green', 'l')
def regist_page(): print my_proces_text.color(''' 注册账户! ''', 'green', 'l')
def welcome_page(): print my_proces_text.color(''' 欢迎光临33网上商城! ''', 'red', 'l')
def printf(self): tmp = self.apellation + ' ' + self.feature.apellation + ' ' + \ self.feature.record.apellation + ' ' + self.feature.record.num print my_proces_text.color(tmp, 'red', 'l') print self.apellation, self.genre, self.feature.apellation, self.feature.genre, self.feature.record.apellation, self.feature.record.genre, self.feature.record.num