def member_login(): while True: memberid = input('進入商店前,請輸入您帳號 (直接按「Enter」則回到上一選單):') conn = db_created.db_connect_host() cursor = conn.cursor() sql = 'SELECT * FROM login_check where memberid = "%s"' % memberid cursor.execute(sql) login_check = cursor.fetchall() sql2 = 'SELECT * FROM member_signup where memberid = "%s"' % memberid cursor.execute(sql2) info = cursor.fetchall() if memberid == '': # 未輸入帳號就結束 cursor.close() conn.close() break elif login_check: # 帳號已存在 cursor.close() conn.close() print('已重複登入系統!,若要結帳請直接按「Enter」則回到上一選單,並選取結帳謝謝') elif not info: # 帳號不存在 cursor.close() conn.close() print('您資料未在系統系統中!,若要註冊請按「Enter」則回到上一選單,並選取註冊謝謝') elif new_recognition.recognition(memberid) > 70: print('登入失敗!請試著正面對著鏡頭不晃動或脫下口罩再辨識一次') elif new_recognition.recognition(memberid) < 20: print('登入成功!歡迎 ' + memberid + '!') print('您現在可進入商店購物!!') cv2.destroyAllWindows() id_num = int(info[0][0]) savetime = datetime.now() msg = { "id": id_num, "Name": memberid, "type": 'login', "Time": savetime } db_created.login(id_num, memberid, savetime) new_mongo_connect.login(id_num, memberid, savetime) new_kafka_producer.kafka_producer('logs', msg, 'login') break else: cv2.destroyAllWindows() print('登入失敗')
def signup_check(): memberid = str(memberid_entry.get()) conn = db_created.db_connect_host() cursor = conn.cursor() sql = 'SELECT * FROM member_signup where memberid = "%s"' % memberid cursor.execute(sql) info = cursor.fetchall() if memberid == '': # 未輸入帳號就結束 cursor.close() conn.close() signup_respond = '請輸入帳號' signup_respond_label.configure(text=signup_respond) new_logout.logout_check() elif info: # 帳號已存在 cursor.close() conn.close() signup_respond = '此帳號已被人使用,請換一個id,註冊謝謝!' signup_respond_label.configure(text=signup_respond) new_logout.logout_check() elif not info: # 獲取人臉資料並建立帳號 sql2 = 'SELECT MAX(id) FROM member_signup;' cursor.execute(sql2) id_num_temp = cursor.fetchall() id_num = 0 if id_num_temp[0][0] == None: id_num = 2501 elif id_num_temp: id_num = id_num_temp[0][0] + 1 new_capture.data_capture(memberid) cv2.destroyAllWindows() new_training.training_data(memberid) model_name = memberid + '.data' msg = { "id": id_num, "Name": memberid, "Model": model_name } db_created.signup(id_num, memberid, model_name) new_mongo_connect.signup(id_num, memberid, model_name) new_kafka_producer.kafka_producer('members', msg, 'signup') signup_respond = '註冊成功!!' signup_respond_label.configure(text=signup_respond) end_respond = '已可退出此頁面!' end_respond_label.configure(text=end_respond) cursor.close() conn.close() new_logout.logout_check()
def member_signup(): while True: memberid = input('請輸入您想註冊的帳號 \n(備註:請以數字 + 英文字母大小組合輸入)\n(直接按「Enter」則回到上一選單)\n 輸入欄位:') conn = db_created.db_connect_host() cursor = conn.cursor() sql = 'SELECT * FROM member_signup where memberid = "%s"' % memberid cursor.execute(sql) info = cursor.fetchall() if memberid == '': # 未輸入帳號就結束 cursor.close() conn.close() break elif info: # 帳號已存在 print('此帳號已被人使用,請換一個id,註冊謝謝!') elif not info : # 獲取人臉資料並建立帳號 sql2 = 'SELECT MAX(id) FROM member_signup;' cursor.execute(sql2) id_num_temp = cursor.fetchall() id_num = 0 if id_num_temp[0][0] ==None : id_num = 2501 elif id_num_temp: id_num = id_num_temp[0][0] + 1 new_capture.data_capture(memberid) cv2.destroyAllWindows() new_training.training_data(memberid) model_name= memberid + '.data' msg = { "id": id_num, "Name": memberid, "Model": model_name } db_created.signup(id_num, memberid, model_name) new_mongo_connect.signup(id_num, memberid, model_name) print('資料傳輸中...') new_kafka_producer.kafka_producer('members',msg,'signup') cursor.close() conn.close() break
def logout_check(): myclientdata = pymongo.MongoClient("mongodb+srv://url") mydbdata = myclientdata['wow'] mycoldata = mydbdata['logs'] results = mycoldata.find({}, sort=[('_id', -1)]).limit(1) log_check = () for result in results: Name = result['Name'] type = result['type'] time = result['Time'] log_check = (Name, type, time) try: if log_check[1] == 'logout': conn = db_created.db_connect_host() cursor = conn.cursor() sql = 'SELECT * FROM login_check where memberid = "%s"' % log_check[ 0] cursor.execute(sql) info = cursor.fetchall() savetime = datetime.strptime(log_check[2].replace('/', '-'), "%Y-%m-%d %H:%M:%S") if info: cursor.close() conn.close() db_created.logout(info[0][0], log_check[0], savetime) return 1 elif not info: return 0 except: return -1
def login_check(): memberid = str(memberid_entry.get()) conn = db_created.db_connect_host() cursor = conn.cursor() sql = 'SELECT * FROM login_check where memberid = "%s"' % memberid cursor.execute(sql) login_check = cursor.fetchall() sql2 = 'SELECT * FROM member_signup where memberid = "%s"' % memberid cursor.execute(sql2) info = cursor.fetchall() if memberid == '': # 未輸入帳號就結束 cursor.close() conn.close() login_respond = '請輸入帳號' respond_label.configure(text=login_respond) new_logout.logout_check() elif login_check: # 帳號已存在 cursor.close() conn.close() login_respond = '已重複登入系統! \n 若要結帳請先退出,回到上一選單並選取結帳謝謝' respond_label.configure(text=login_respond) new_logout.logout_check() elif not info: # 帳號不存在 cursor.close() conn.close() login_respond ='您資料未在系統系統中!\n 若要註冊請先退出,回到上一選單,並選取註冊謝謝' respond_label.configure(text=login_respond) new_logout.logout_check() elif new_recognition.recognition(memberid) > 70: login_respond = '登入失敗!請試著正面對著鏡頭不晃動或脫下口罩再辨識一次' respond_label.configure(text=login_respond) new_logout.logout_check() elif new_recognition.recognition(memberid) < 30: new_logout.logout_check() login_respond = '登入成功!歡迎 ' + memberid + '!'+'\n歡迎光臨,您現在可進入商店購物!! ' respond_label.configure(text=login_respond) cv2.destroyAllWindows() id_num = int(info[0][0]) savetime = datetime.now() msg = { "id": id_num, "Name": memberid, "type": 'login', "Time": savetime } db_created.login(id_num, memberid, savetime) new_mongo_connect.login(id_num, memberid, savetime) new_kafka_producer.kafka_producer('logs',msg, 'login') else: cv2.destroyAllWindows() login_respond ='登入失敗' respond_label.configure(text=login_respond) new_logout.logout_check()