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 回答