flask-httpauto add roles based on a model field

I have two models:

  • Students

  • Teacher Both of them have a role field

    role = db.Column('role', db.VARCHAR(255), nullable=False)
    

Now I can verify only a user who is a teacher

    @auth.verify_password
    def verify_password(email, password):
        if not (email and password):
            return False
        userTest = Teacher.query.filter_by(email=email).first()
        # print(userTest, 'hi')
        if userTest is None:
            return False
        if userTest:
            return userTest.password_is_valid(password)
        return False


        @app.route('/teachers/<int:id>/', methods=['GET', 'DELETE'])
        @auth.login_required
        @auth.check_roles <===== I want to implement something like this
        def teacher(id):
           ...

I was wondering whether I can write one more @auth.login_required decorator so it will check roles.

@auth.login_required_student
@auth.login_required_teacher


from Recent Questions - Stack Overflow https://ift.tt/37Q3Hm2
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)