Ejemplo n.º 1
0
    def check_user_credentials_with_credentials(user_id, token):
        # Check token status
        status = TokenSerializer.verify_auth_token(token, user_id)

        # Is token is expired?
        if status == SignatureExpired:
            # Yes: return error status
            return Constants.error_token_expired()
        # Is toke not valid?
        elif status == BadSignature:
            # Yes: return error status
            return Constants.error_token_not_valid()

        # Try to find user with received ID
        person_model = PersonModel.query.filter_by(person_id=user_id).first()

        # Have we user with received ID?
        if person_model is None:
            # No we haven't: return error status
            return  Constants.error_no_user_id()

        # Is received token correct?
        if person_model.token != token:
            # No: return error status
            return  Constants.error_token_not_valid()

        # If everything is Ok - return person model
        return person_model