Пример #1
0
    def post(self):
        uname = self.get_argument("username")
        upass = self.get_argument("password")
        if not uname:
            return self.render_json(code=1, msg=u"请填写用户名")
        if not upass:
            return self.render_json(code=1, msg=u"请填写密码")

        enpasswd = md5(upass.encode()).hexdigest()

        opr = self.db.query(models.TrOperator).filter_by(
            operator_name=uname,
            operator_pass=enpasswd
        ).first()
        if not opr:
            return self.render_json(code=1, msg=u"用户名密码不符")

        if opr.operator_status == 1:
            return self.render_json(code=1, msg=u"该操作员账号已被停用")

        self.set_session_user(uname, self.request.remote_ip, opr.operator_type, utils.get_currtime())

        if opr.operator_type == 1:
            for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=uname):
                permit.bind_opr(rule.operator_name, rule.rule_path)

        self.add_oplog(u'操作员(%s)登陆' % (uname))
        self.db.commit()

        self.render_json(code=0, msg="ok")
Пример #2
0
    def post(self):
        nodes = [(n.node_name, n.node_desc) for n in self.db.query(models.TrNode)]
        products = [(p.id,p.product_name) for p in self.db.query(models.TrProduct)]
        form = operator_form.operator_update_form(nodes,products)
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.TrOperatorRule.rule_path).filter_by(operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("base_form.html", form=form,rules=rules)
        operator = self.db.query(models.TrOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        self.db.query(models.TrOperatorNodes).filter_by(operator_name=operator.operator_name).delete()
        for node in self.get_arguments("operator_nodes"):
            onode = models.TrOperatorNodes()
            onode.operator_name = form.d.operator_name
            onode.node_name = node
            self.db.add(onode)

        self.db.query(models.TrOperatorProducts).filter_by(operator_name=operator.operator_name).delete()
        for product_id in self.get_arguments("operator_products"):
            oproduct = models.TrOperatorProducts()
            oproduct.operator_name = form.d.operator_name
            oproduct.product_id = product_id
            self.db.add(oproduct)

        self.add_oplog(u'修改操作员%s信息' % utils.safeunicode(operator.operator_name))

        # update rules
        self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/admin/operator",permanent=False)
Пример #3
0
    def init_route(self):
        handler_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "admin")
        load_handlers(handler_path=handler_path, pkg_prefix="toughradius.console.admin")

        chandler_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "customer")
        load_handlers(handler_path=chandler_path, pkg_prefix="toughradius.console.customer")

        conn = self.db()
        try:
            oprs = conn.query(models.TrOperator)
            for opr in oprs:
                if opr.operator_type > 0:
                    for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=opr.operator_name):
                        permit.bind_opr(rule.operator_name, rule.rule_path)
                elif opr.operator_type == 0:  # 超级管理员授权所有
                    permit.bind_super(opr.operator_name)
        except Exception as err:
            self.syslog.error("init route error , %s" % str(err))
        finally:
            conn.close()