Exemplo n.º 1
0
    def master_add_course_handler(self, data):
        masterIndex = int(data.split(";")[0])
        addList = data.split(";")[2].split(",")
        courseName = addList[0]
        startDate = addList[1]
        endDate = addList[2]
        banList = addList[3].split("*")
        allowList = addList[4].split("*")
        userList = addList[5].split("*")
        print(masterIndex,courseName,startDate, endDate, banList, allowList, userList)
        try:
            try:
                dao.add(insert_course(masterIndex, courseName, startDate, endDate))
                dao.commit()
            except Exception as e:
                dao.rollback()
                print(e)
                self.request.send("0".encode('utf-8'))
                return 
            testIndex = select_course_index(courseName)

            if len(userList[0]) is not 0:
                for userInfo in userList:
                    userInfo = userInfo.split('$')
                    try:
                        userIndex = select_user_index(userInfo[0])
                    except:
                        try:
                            dao.add(insert_user(userInfo[0], userInfo[1]))
                            dao.commit()
                        except Exception as e:
                            dao.rollback()
                            print(e)
                            self.request.send("-1".encode('utf-8'))
                            return
                        userIndex = select_user_index(userInfo[0])
                    dao.add(insert_user_in_course(testIndex, userIndex))

            if len(banList[0]) is not 0:
                for banProgram in banList:
                    dao.add(insert_ban_list_in_course(testIndex, int(banProgram)))

            if len(allowList[0]) is not 0:
                for allowSite in allowList:
                    dao.add(insert_allow_list_in_course(testIndex, int(allowSite)))

            dao.commit()
            self.request.send("1".encode('utf-8'))
        except Exception as e:
            print(e)
            dao.rollback()
            self.request.send("0".encode('utf-8'))
Exemplo n.º 2
0
    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'))
Exemplo n.º 3
0
    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'))