0

ドメインを介してそれらをフィルタリングできましたが、さらにフィルタリングするために正規表現を使用したい場合。それをしてもいいですか?私は最近よく調べています。部分的なパイプラインを作成することが解決策だと思いました。しかし、ドキュメントが貧弱なためです。目標を達成できませんでした。ログインプロセスが追加された機能を完全にオーバーライドするため、ミドルウェアを追加しても役に立ちませんでした。私はこのようなことをしたいと思っていました。

ミドルウェア.py

class MyMiddleware(SocialAuthExceptionMiddleware):
    def process_exception(self, request, exception):
        if type(exception) == AuthForbidden:
            return render(request, "app/needlogin.html", {})

    def process_request(self,request):
        if request.user.is_authenticated():
            name = request.user.username.split('@')[0]
            roll=[]
            for i in name:
                if i.isdigit():
                    roll.append(i)
            if int(roll[1])<3:
                auth_logout(request)
                return render(request,"app/notlogin.html",{})
            # else:
                # return render(request, "app/needlogin.html",{})

問題は、特にログイン要求ではなく、すべての要求を処理することです。また、動作しません。私が間違っているところを指摘してください。

助けていただければ幸いです。ありがとう!

4

2 に答える 2

1

そのためにはパイプライン関数が必要です。これでうまくいくはずの簡単なものです。

from social.exceptions import AuthForbidden

def email_check(strategy, details, *args, **kwargs):
    if not is_valid_email(details.get(email)):
        raise AuthForbidden(strategy.backend)

'social.pipeline.social_auth.auth_allowed',次に、次のように、エントリの後にこの関数を貼り付けます。

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'import.path.to.email_check',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details'
)
于 2014-06-07T15:53:37.860 に答える
0

うん。それで、それはあるべきように機能していました。私は正しい状態をテストしていませんでした。

于 2014-06-08T17:09:20.517 に答える