Пример #1
0
    def post(self, table):
        userid = int(tornado.escape.xhtml_escape(self.current_user))
        _id = int(self.get_argument('id', 0))

        if table == 'vote_accounts':
            user = vote_model.db.get("select * from users where id=%d" % userid)
            if user is None or user.access_vote == 0:
                self.write(u"你没有权限进行该操作")
                return

            display_id = self.get_body_argument('display_id')
            app_id = MySQLdb.escape_string(self.get_body_argument('app_id'))
            rlt = vote_model.db.get("select * from vote_accounts where id=%d" % _id)

            if rlt is None:
                exist = vote_model.db.get("select * from vote_accounts where app_id='%s'" % app_id)
                if exist is not None:
                    self.write(u"该 app_id 已被登记,请使用其他公众号")
                    return
                exist = vote_model.db.get("select * from school_accounts where app_id='%s'" % app_id)
                if exist is not None:
                    self.write(u"该 app_id 已被登记,请使用其他公众号")
                    return

                account_info = get_account_info(display_id)

                if account_info is None:
                    self.write(u"找不到该公众号")
                    return

                # 添加
                sql = "insert into vote_accounts(" \
                      "app_id, app_secret, token, aes_key, admin_id, name, display_id, avatar_url, qrcode_url, active) " \
                      "values('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %s)" \
                      % (app_id,
                         MySQLdb.escape_string(self.get_body_argument('app_secret')),
                         MySQLdb.escape_string(self.get_body_argument('token')),
                         "", userid,
                         MySQLdb.escape_string(account_info['name'].encode('utf8')),
                         MySQLdb.escape_string(display_id),
                         MySQLdb.escape_string(account_info['logo']),
                         MySQLdb.escape_string(account_info['qr_code']),
                         "false" if self.get_body_argument('active', None) is None else "true")
                try:
                    vote_model.db.insert(sql)
                    self.redirect('/%s' % table, permanent=True)
                except Exception, e:
                    print Exception, ":", e
                    self.write(u'操作失败,请确认你填写的数据无误')

            else:
                # 编辑
                if not rlt.display_id == display_id:
                    # 公众号改变,重新获取账户信息
                    account_info = get_account_info(display_id)
                else:
                    account_info = dict(name=rlt.name, logo=rlt.avatar_url, qr_code=rlt.qrcode_url)

                sql = "update vote_accounts set app_id='%s', app_secret='%s', token='%s', name='%s', " \
                      "display_id='%s', avatar_url='%s', qrcode_url = '%s', active = %s where id=%d" \
                      % (MySQLdb.escape_string(self.get_body_argument('app_id')),
                         MySQLdb.escape_string(self.get_body_argument('app_secret')),
                         MySQLdb.escape_string(self.get_body_argument('token')),
                         MySQLdb.escape_string(account_info['name'].encode('utf8')),
                         MySQLdb.escape_string(display_id),
                         MySQLdb.escape_string(account_info['logo']),
                         MySQLdb.escape_string(account_info['qr_code']),
                         "false" if self.get_body_argument('active', None) is None else "true",
                         _id)

                try:
                    vote_model.db.update(sql)
                    self.redirect('/%s' % table, permanent=True)
                except Exception, e:
                    print Exception, ":", e
                    self.write(u'操作失败,请确认你填写的数据无误')
Пример #2
0
            app_id = MySQLdb.escape_string(self.get_body_argument('app_id'))
            rlt = vote_model.db.get("select * from school_accounts where id=%d" % _id)

            if rlt is None:
                # 添加

                exist = vote_model.db.get("select * from vote_accounts where app_id='%s'" % app_id)
                if exist is not None:
                    self.write(u"该 app_id 已被登记,请使用其他公众号")
                    return
                exist = vote_model.db.get("select * from school_accounts where app_id='%s'" % app_id)
                if exist is not None:
                    self.write(u"该 app_id 已被登记,请使用其他公众号")
                    return

                account_info = get_account_info(display_id)

                if account_info is None:
                    self.write(u"找不到该公众号")
                    return

                sql = "insert into school_accounts(" \
                      "app_id, app_secret, token, aes_key, admin_id, name, display_id, avatar_url, qrcode_url, active, " \
                      "school_name, voting_count, intro_url, intro_img_url, vote_account_id) " \
                      "values('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %s, " \
                      "'%s', %d, '%s', '%s', '%s')" \
                      % (MySQLdb.escape_string(self.get_body_argument('app_id')),
                         MySQLdb.escape_string(self.get_body_argument('app_secret')),
                         MySQLdb.escape_string(self.get_body_argument('token')),
                         "", userid,
                         MySQLdb.escape_string(account_info['name'].encode('utf8')),