的一種方式。
def create_user(strategy, details, user=None, *args, **kwargs):
if user:
return {'is_new': False}
allowed_emails = get_list_of_emails()
fields = dict((name, kwargs.get(name, details.get(name)))
for name in strategy.setting('USER_FIELDS', USER_FIELDS))
if not fields:
return
if fields[email] in allowed_emails:
return {
'is_new': True,
'user': strategy.create_user(**fields)
}
return
這種方法get_list_of_emails()
是用來作爲一種方法來從文件加載OU中的電子郵件從數據庫:
你可以像覆蓋create_user。它需要返回一個電子郵件列表。
然後,在你的設置中SOCIAL_AUTH_PIPELINE更換create_user到您的自定義的方法:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'path.to.my.method.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)
這樣你就可以保持domais白名單,然後保存您想某處的電子郵件,在那裏你可以加載它們該方法get_list_of_emails()
更多的docs
這個列表中,您必須是域的依賴?我的意思是,你會允許來自特定域名的所有電子郵件或只是特定的電子郵件地址? –
我想允許所有人**爲@ companyname.net,並且只允許來自其他域的某些特定人。 –