def login_handler(self, data): id = data.split(";")[2].split(",")[0] password = data.split(";")[2].split(",")[1] courses = '' if len(password) != 0: try: masterInfo = select_master_check(id) idIndex = masterInfo.index if check_password_hash(masterInfo.password, TripleDES.encrypt(str(password))) is False: self.request.send('0'.encode('utf-8')) return except: self.request.send('0'.encode('utf-8')) return try: courseList = select_unfinished_test_course_for_master(idIndex) for courseInfo in courseList: userCount = select_user_count(courseInfo.index) banList = select_ban_list_index(courseInfo.index) allowList = select_allow_list_index(courseInfo.index) banList = str(banList).strip('[]').replace(' ','').replace('(','').replace(',)','').replace(',','*') allowList = str(allowList).strip('[]').replace(' ','').replace('(','').replace(',)','').replace(',','*') courseData = courseInfo.testName + "," + str(courseInfo.startDate) + "," + str(courseInfo.endDate) + "," + banList + "," + allowList + "," + str(userCount) courses = courses + '^' + courseData except: courses = '' courses = courses.lstrip('^') else: try: idIndex = select_user_index(id) except: self.request.send('0'.encode('utf-8')) return try: courseList = select_unfinished_test_course_for_user(idIndex) if len(courseList) is 0: self.request.send('-1'.encode('utf-8')) return courses = str(courseList).strip('[]').replace(' ','').replace('(','').replace(',)','').replace("'", '') except: self.request.send('-1'.encode('utf-8')) return sendData = str(idIndex)+"^"+courses self.request.send(sendData.encode('utf-8'))
def master_modify_course_handler(self, data): updateList = data.split(";")[2].split(",") courseName = updateList[0] startDate = updateList[1] endDate = updateList[2] banList = updateList[3].split("*") allowList = updateList[4].split("*") userList = updateList[5].split("*") courseIndex = select_course_index(courseName) try: if len(userList[0]) is not 0: for userInfo in userList: userInfo = userInfo.split('$') try: userIndex = select_user_index(userInfo[0]) except: dao.add(insert_user(userInfo[0], userInfo[1])) dao.commit() userIndex = select_user_index(userInfo[0]) try: existUserIndex = select_user_in_course(courseIndex, userIndex) except Exception as e: dao.add(insert_user_in_course(courseIndex, userIndex)) dao.commit() delete_ban_list_in_course(courseIndex) delete_allow_list_in_course(courseIndex) except Exception as e: dao.rollback() self.request.send("-1".encode('utf-8')) return try: modify_course(courseName = courseName, startDate = startDate, endDate = endDate) if len(banList[0]) is not 0: for banIndex in banList: try: dao.add(insert_ban_list_in_course(courseIndex, int(banIndex))) except: modify_ban_list_in_course(courseIndex, int(banIndex)) if len(allowList[0]) is not 0: for webIndex in allowList: try: dao.add(insert_allow_list_in_course(courseIndex, int(webIndex))) except: modify_allow_list_in_course(courseIndex, int(webIndex)) dao.commit() except: dao.rollback() self.request.send("-1".encode('utf-8')) return try: userCount = select_user_count(courseIndex) except Exception as e: self.request.send("-1".encode('utf-8')) self.request.send(str(userCount).encode('utf-8'))