示例#1
0
    def wrapper(*args, **kwargs):
        self = args[0]
        auth_header = self.request.headers.get('Proxy-Authorization', None)
        if auth_header is not None:
            customer = CustomerModel()
            auth_mode, auth_base64 = auth_header.split(' ', 1)
            assert auth_mode == 'Basic'
            username, password = auth_base64.decode('base64').split(':', 1)
            self.username = username
            if customer.checkPassword(username, password):
                if customer.checkTraffic(username):
                    return func(*args, **kwargs)
                else:
                    if self.request.headers.has_key('Proxy-Authorization'):
                        del self.request.headers['Proxy-Authorization']
                    self.set_status(407)
                    self.set_header('Proxy-Authenticate',
                                    'Basic realm="%s"' % no_money)
                    logger.info(username + ':' + no_money)
                    self.write("请交钱")
                    self.finish()
            else:
                self.set_status(407)
                self.set_header('Proxy-Authenticate',
                                'Basic realm="%s"' % fail)
                logger.info(username + ':' + fail)
                self.finish()

        else:
            self.set_status(407)
            self.set_header('Proxy-Authenticate', 'Basic realm="%s"' % realm)
            logger.info(realm)
            self.finish()
示例#2
0
    def wrapper(*args, **kwargs):
        self = args[0]
        auth_header = self.request.headers.get('Proxy-Authorization', None)
        if auth_header is not None:
            customer = CustomerModel()
            auth_mode, auth_base64 = auth_header.split(' ', 1)
            assert auth_mode == 'Basic'
            username, password = auth_base64.decode('base64').split(':', 1)
            self.username = username
            if customer.checkPassword(username, password):
                if customer.checkTraffic(username):
                    return func(*args, **kwargs)
                else:
                    if self.request.headers.has_key('Proxy-Authorization'):
                        del self.request.headers['Proxy-Authorization']
                    self.set_status(407)
                    self.set_header('Proxy-Authenticate', 'Basic realm="%s"' % no_money)
                    logger.info(username + ':' + no_money)
                    self.write("请交钱")
                    self.finish()
            else:
                self.set_status(407)
                self.set_header('Proxy-Authenticate', 'Basic realm="%s"' % fail)
                logger.info(username + ':' + fail)
                self.finish()

        else:
            self.set_status(407)
            self.set_header('Proxy-Authenticate', 'Basic realm="%s"' % realm)
            logger.info(realm)
            self.finish()
示例#3
0
def register_customer():
    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        full_name = request.form["full_name"]
        email = request.form["email"]
        phone_number = request.form["phone_number"]
        address = request.form["address"]
        new_customer = CustomerModel(full_name=full_name, email=email, phone_number=phone_number, address=address)
        new_customer.save()
示例#4
0
    def post(self):

        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True)
        data = parser.parse_args()
        current_user_id = get_jwt_identity()
        new_customer = CustomerModel(name=data['name'],
                                     user_id=current_user_id)
        new_customer.save()
        return {'_id': new_customer.hex_id}, 200
示例#5
0
 def get_by_document(self, document):
     ps = self.c.execute('SELECT * FROM document WHERE document=?',
                         (document, ))
     try:
         return CustomerModel.fromDB(c.fetchall()[0])
     except IndexError:
         return False
示例#6
0
 def create(self, customer: CustomerModel):
     db_tuple = customer.toDB()
     try:
         self.c.execute("INSERT INTO customers VALUES (?,?,?,?,?,?)",
                        db_tuple)
         self.db.commit()
     except sqlite3.IntegrityError:
         self.db.rollback()
         raise sqlite3.IntegrityError(
             f'customer.document: {customer.document} already exists in db!'
         )
示例#7
0
 def sum_traffic(self, traffic):
     """重写父累流量统计"""
     customer = CustomerModel()
     return customer.computeTraffic(self.username, -traffic)
示例#8
0
 def sum_traffic(self, traffic):
     """重写父累流量统计"""
     customer = CustomerModel()
     return customer.computeTraffic(self.username, -traffic)
示例#9
0
 def mutate(self, info, name):
     customer = CustomerModel(name=name)
     db_session.add(customer)
     db_session.commit()
     return addCustomer(name=customer.name, country=customer.country)
示例#10
0
 def search(self, **kwargs):
     query = 'SELECT * FROM cutomers WHERE (' + self.build_query(
         kwargs) + ')'
     results = self.c.execute(query)
     return [CustomerModel.fromDB(r) for r in results.fetchall()]