Example #1
0
    def system():
        ip_address = get_remote_addr()
        user_count = User.query.count()
        book_count = Book.query.count()

        return flask.render_template('system.html',
                                     ip_address=ip_address,
                                     user_count=user_count,
                                     book_count=book_count)
Example #2
0
    def validate_password(self, field):
        address = get_remote_addr()
        whitelist = os.environ.get('WHITELIST_IPADDRESS', '127.0.0.1')

        # If you are in the debug mode or from office network (developer)
        if not app.debug and not ip_address_in(address, whitelist):
            raise StopValidation(f'your ip address isn\'t in the {whitelist}.')

        user = User.query.filter_by(username=self.username.data).first()
        if not user or not user.check_password(field.data):
            raise StopValidation('Username or password error.')
Example #3
0
    def validate_password(self, field):
        address = get_remote_addr()  # X-Forwarded-For
        whitelist = os.environ.get('WHITELIST_IPADDRESS', '127.0.0.1')

        #whitelist={   10.0.0.0 – 10.255.255.255
        #    127.0.0.0 – 127.255.255.255
        #    172.16.0.0 – 172.31.255.255
        #    192.168.0.0 – 192.168.255.255
        #    18.213.16.123  }

        # If you are in the debug mode or from office network (developer)
        if not app.debug and not ip_address_in(address, whitelist):
            raise StopValidation('your ip address isn\'t in the {whitelist}.')

        user = User.query.filter_by(username=self.username.data).first()
        if not user or not user.check_password(field.data):  # no such user or
            raise StopValidation('Username or password error.')