Beispiel #1
0
    def post_response(self):
        gbooks = None
        sendflag = False
        if self.request.remote_ip:
            try:
                gbooks = Database.get_gbook_for_ip(self.request.remote_ip)
            except:
                pass

        if len(gbooks) == 3:
            _a = str(gbooks[0].createdAt)[:-3]
            _b = str(gbooks[1].createdAt)[:-3]
            _c = str(gbooks[2].createdAt)[:-3]
            if _a == _b == _c:
                sendflag = True
                Database.create_black(self.request.remote_ip)
                Database.delete_gbook(self.request.remote_ip)

        form = GbookForm(self.fdata)
        res = dict(code=0)
        if (not sendflag) and form.validate() and (form.chkcode.data.lower() == self.session["chkcode"].lower()):
            if Database.create_gbook(form, self.request.remote_ip):
                res["code"] = 1
        else:
            res = form.errors
            res["code"] = 0
        self.write(res)
Beispiel #2
0
    def on_message(self, message):
        try:
            data = json.loads(message)
            data['datenow'] = datetime.datetime.now().strftime(
                "%Y-%m-%d %H:%M:%S")
            content = json.dumps(data)

            sendflag = False
            if data['code'] == 2:
                msgs = Database.get_msg_for_ip(self.session.conn_info.ip)
                if len(msgs) == 5:
                    _a = str(msgs[0].createdAt)[:-3]
                    _b = str(msgs[1].createdAt)[:-3]
                    _c = str(msgs[2].createdAt)[:-3]
                    _d = str(msgs[3].createdAt)[:-3]
                    _e = str(msgs[4].createdAt)[:-3]

                    if _a == _b == _c == _d == _e:
                        sendflag = True
                        Database.create_black(self.request.remote_ip)
                        Database.delete_gbook(self.request.remote_ip)

                if not sendflag:
                    Database.create_msg(int(data['vid']), data["vsb"], content,
                                        self.session.conn_info.ip)

            self.broadcast(self.waiters, content)
        except:
            pass