本文整理匯總了Python中core.models.User.set_unusable_password方法的典型用法代碼示例。如果您正苦於以下問題:Python User.set_unusable_password方法的具體用法?Python User.set_unusable_password怎麽用?Python User.set_unusable_password使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core.models.User
的用法示例。
在下文中一共展示了User.set_unusable_password方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: authenticate
# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import set_unusable_password [as 別名]
def authenticate(self, saml_authentication=None):
if not saml_authentication: # Using another authentication method
return None
if saml_authentication.is_authenticated():
attributes = saml_authentication.get_attributes()
user_changed = False
try:
user = User.objects.get(username=saml_authentication.get_attributes()['uid'][0])
except User.DoesNotExist:
user = User(username=saml_authentication.get_attributes()['uid'][0])
user.set_unusable_password()
user.username = attributes['uid'][0]
map_fields = {
'realname': 'cn',
'email': 'mail'
}
# ensure realname for users from webid don't contain unverified note
if 'cn' in attributes:
attributes['cn'][0] = attributes['cn'][0].replace(' (unverified)', '')
for field, samlfield in map_fields.items():
if getattr(user, field) != attributes[samlfield][0]:
setattr(user, field, attributes[samlfield][0])
user_changed = True
if user_changed:
user.save()
return user
return None