示例#1
0
    def post(self):
        errors = "Nothing"
        command = "query_order_all " + self.current_user.decode()
        print(command)
        link_command(command)
        n = int(link_read())
        retval = {'errors': 'Nothing'}
        if(n):
            errors = "Success"
            retval["cnt"] = n
            for i in range(0,n):
                ii = str(i)
                line = link_read()
                list = line.split()
                retval["seatcnt" + ii] = 1
                retval["code" + ii] = list[0]
                retval["startpos" + ii] = list[1]
                retval["seatdata" + ii + "|0"] = list[2]
                retval["start" + ii] = list[3]
                retval["endpos" + ii] = list[4]
                retval["end" + ii] = list[5]#多一天则加 <span class='day-plus'>+1d</span>
                if(list[6] == '1'): retval["end" + ii]+="<span class='day-plus'>+1d</span>"
                retval["time" + ii] = list[7]
                retval["seattype" + ii + "|0"] = list[8]

        self.set_header("Content-Type","application/json")

        retval['errors'] = errors
        yield self.write(json.dumps(retval))
示例#2
0
 def get(self):
     if(self.current_user == None or self.current_user.decode() != "2019"):
         BaseHandler.get(self)
     else:
         link_command("exit")
         BaseHandler.get(self)
     
     #yield self.render('manage.html', title = 'manage', user = self.current_user)
示例#3
0
 def post(self):
     command = self.request.arguments['command'][0].decode()
     list = command.split()
     if(command!="" and list[0]=="buy_ticket"):
         line=command[10:]
     print(command)
     link_command(command)
     link_read();
示例#4
0
 def isverify(self):
     command = "query_profile " + self.current_user.decode()
     link_command(command)
     line = link_read()
     list = line.split()
     if ("1" == list[1]):
         return True
     else:
         return False
示例#5
0
 def checkverify(self, code):
     command = "query_profile " + self.current_user
     link_command(command)
     line = link_read()
     list = line.split()
     if (code == list[0]):
         command2 = "register " + str(code) + " Zero 1 Zero"
         link_command(command2)
         link_read()
         return True
     else:
         return False
示例#6
0
    def register(self, username, password, email, phone):
        command = "INSERT INTO user (username, password, email, phone) VALUES('{}', '{}', '{}', '{}')"
        cursor.execute(
            command.format(
                username,
                hashlib.sha256(password.encode('utf-8')).hexdigest(), email,
                phone))
        conn.commit()

        code = random.randint(100000, 999999)

        Sendmail(email, code)

        command2 = "register " + str(code) + " Zero 0 Zero"
        link_command(command2)
        link_read()
示例#7
0
    def resendemail(self):
        command = "query_profile " + self.current_user.decode()
        link_command(command)
        line = link_read()
        list = line.split()
        n = int(list[1])
        if (n < -4):
            return False
        else:
            result = queryById(self.current_user.decode()).fetchone()

            code = random.randint(100000, 999999)

            Sendmail(result[3], code)
            n -= 1
            command2 = "modify_profile " + self.current_user.decode(
            ) + " " + str(code) + " Zero " + str(n) + " Zero"
            link_command(command2)
            link_read()
            return True
示例#8
0
class ManageHandler(BaseHandler):
    @tornado.gen.coroutine
    def get(self):
        if(self.current_user == None or self.current_user.decode() != "2019"):
            BaseHandler.get(self)
        else:
            yield self.render('manage.html', title = 'manage', user = self.current_user)
        
        #yield self.render('manage.html', title = 'manage', user = self.current_user)

    @tornado.gen.coroutine
    def post(self):
        case = int(self.request.arguments['case'][0].decode())
        errors = "Failed"
        retval = {'errors': 'Failed'}
        if(case == 0):
            retval["case"] = 0
            form = SearchForm2(self.request.arguments)

            if form.validate():
                errors = "Nothing"
                search_id = self.request.arguments['search_id'][0].decode()
                command = "query_train " + search_id
                retval["train_id"] = search_id

                print(command)

                link_command(command)

                line = link_read()
                list = line.split()

                if(list[0] != '0'):
                    errors = "Success"
                    retval["train_name"] = list[1]
                    retval["train_type"] = list[2]
                    n = int(list[3])
                    retval["station_cnt"] = n
                    m = int(list[4])
                    retval["seat_cnt"] = m
                    cur = 5
                    for i in range(0,m):
                        ii = str(i)
                        retval["seattype" + ii] = list[cur]
                        cur+=1
                    retval["onsale"] = int(list[cur])

                    for i in range(0,n):
                        ii = str(i)
                        line = link_read()
                        list = line.split()
                        retval["station" + ii] = list[0]
                        for j in range(0,3):
                            jj = str(j)
                            retval["time" + ii + "s" + jj] = list[j + 1]
                        for j in range(0,m):
                            jj = str(j)
                            retval["price" + ii + "s" + jj] = list[j + 4]

            else: 
                retval = form.errors
        elif(case == 1):
            retval["case"] = 1
            form = SearchForm2(self.request.arguments)

            if form.validate():
                errors = "Hasone"
                search_id = self.request.arguments['search_id'][0].decode()
                command = "query_train " + search_id
                retval["train_id"] = search_id
                
                link_command(command)
                line = link_read()
                list = line.split()

                if(list[0] == '0'):
                    errors = "Success"
                else:
                    n = int(list[3])
                    for i in range(0,n):
                        link_read()
            else: 
                retval = form.errors
        elif(case == 2):
            command = "sale_train " + self.request.arguments['train_id'][0].decode()
            link_command(command)
            line = link_read()
            if(line == "0"):
                errors = "Failed"
            else:
                errors = "Success"
        elif(case == 3):
            retval["case"] = 3
            if(self.request.arguments['isempty'][0].decode()=="1"):
                errors = "Empty"
            else:
                train_id = self.request.arguments['train_id'][0].decode()
                train_name = self.request.arguments['train_id'][0].decode()
                command="modify_train "+self.request.arguments['train_id'][0].decode()+" "+self.request.arguments['train_name'][0].decode()+" "+self.request.arguments['train_type'][0].decode()+" "+self.request.arguments['stationcnt'][0].decode()+" "+self.request.arguments['seatcnt'][0].decode()+" "+self.request.arguments['seattype'][0].decode()+" "+self.request.arguments['stationlist'][0].decode()
                print(command)
                link_command(command)
                line = link_read()
                if(line == "0"):
                    errors = "Failed"
                else:
                    errors = "Success"
            
        elif(case == 4):
            command = "delete_train " + self.request.arguments['train_id'][0].decode()
            link_command(command)
            line = link_read()
            if(line == "0"):
                errors = "Failed"
            else:
                errors = "Success"
        elif(case == 5):
            retval["case"] = 5
            if(self.request.arguments['isempty'][0].decode()=="1"):
                errors = "Empty"
            else:
                train_id = self.request.arguments['train_id'][0].decode()
                train_name = self.request.arguments['train_id'][0].decode()
                command="modify_train "+self.request.arguments['train_id'][0].decode()+" "+self.request.arguments['train_name'][0].decode()+" "+self.request.arguments['train_type'][0].decode()+" "+self.request.arguments['stationcnt'][0].decode()+" "+self.request.arguments['seatcnt'][0].decode()+" "+self.request.arguments['seattype'][0].decode()+" "+self.request.arguments['stationlist'][0].decode()
                print(command)
                link_command(command)
                line = link_read()
                if(line == "0"):
                    errors = "Failed"
                else:
                    errors = "Success"

        self.set_header("Content-Type","application/json")

        retval['errors'] = errors
        yield self.write(json.dumps(retval))
示例#9
0
    def post(self):
        errors = "Failed"
        form = SearchForm(self.request.arguments)
        if(self.request.arguments['type'][0].decode() == ''):
            errors = "Nothing"
            retval = form.errors
            self.set_header("Content-Type","application/json")
            retval['errors'] = errors
            yield self.write(json.dumps(retval))
            return


        if form.validate():
            errors = "Nothing"
            retval = form.errors

            require = self.request.arguments['froms'][0].decode() + ' ' + self.request.arguments['arrival'][0].decode() + ' ' + self.request.arguments['date'][0].decode() + ' '
            
            require+=self.request.arguments['type'][0].decode()
            command = require

            if(self.request.arguments['available'][0].decode() == "true" and self.request.arguments['change'][0].decode() == "true"):
                command = "query_ticket_transfer_available " + require
            elif(self.request.arguments['available'][0].decode() == "true"):
                command = "query_ticket_available " + require
            elif(self.request.arguments['change'][0].decode() == "true"):
                command = "query_ticket_transfer " + require
            else:
                command = "query_ticket_all " + require
            
            print(command)

            link_command(command)

            n = int(link_read())
            
            if(n>0):
                errors = "Success"
                #retval["user"] = self.current_user.decode()
                retval["cnt"] = n
                for i in range(0,n):
                    ii = str(i)
                    line = link_read()
                    list = line.split()
                    m = int(link_read())
                    retval["seatcnt" + ii] = m
                    retval["code" + ii] = list[0]
                    retval["startpos" + ii] = list[1]
                    retval["start" + ii] = list[2]
                    retval["endpos" + ii] = list[3]
                    retval["end" + ii] = list[4]#多一天则加 <span class='day-plus'>+1d</span>
                    if(list[5] == '1'): retval["end" + ii]+="<span class='day-plus'>+1d</span>"
                    retval["time" + ii] = list[6]
                    for j in range(0,m):
                        jj = str(j)
                        line = link_read()
                        list = line.split()
                        retval["seattype" + ii + "|" + jj] = list[0]
                        if(list[1] == '0'):
                            retval["seatclass" + ii + "|" + jj] = "seat-sold-out sold-out-warn"
                            retval["seatbutton" + ii + "|" + jj] = "SOLD OUT"
                            retval["seatleft" + ii + "|" + jj] = ""
                            retval["seatname" + ii + "|" + jj] = ""
                        else:
                            retval["seatclass" + ii + "|" + jj] = " "
                            retval["seatbutton" + ii + "|" + jj] = "BOOK"
                            retval["seatleft" + ii + "|" + jj] = list[1] + " left"
                            retval["seatname" + ii + "|" + jj] = "buy_ticket"

                        retval["seatmoney" + ii + "|" + jj] = list[2]

        else: 
            retval = form.errors

        self.set_header("Content-Type","application/json")

        retval['errors'] = errors
        yield self.write(json.dumps(retval))