本文整理汇总了Python中indico.modules.auth.Identity.password_hash方法的典型用法代码示例。如果您正苦于以下问题:Python Identity.password_hash方法的具体用法?Python Identity.password_hash怎么用?Python Identity.password_hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.auth.Identity
的用法示例。
在下文中一共展示了Identity.password_hash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migrate_users
# 需要导入模块: from indico.modules.auth import Identity [as 别名]
# 或者: from indico.modules.auth.Identity import password_hash [as 别名]
def migrate_users(self):
print cformat('%{white!}migrating users')
seen_identities = set()
for avatar in committing_iterator(self._iter_avatars(), 5000):
if getattr(avatar, '_mergeTo', None):
print cformat('%{red!}!!!%{reset} '
'%{yellow!}Skipping {} - merged into {}').format(avatar.id, avatar._mergeTo.id)
continue
elif avatar.status == 'Not confirmed':
print cformat('%{yellow!}!!!%{reset} '
'%{yellow!}Skipping {} - not activated').format(avatar.id)
continue
elif not avatar.name.strip() and not avatar.surName.strip():
links = {(obj, role): list(objs)
for obj, x in avatar.linkedTo.iteritems()
for role, objs in x.iteritems()
if objs}
if not avatar.identities and not links:
print cformat('%{yellow!}!!!%{reset} '
'%{yellow!}Skipping {} - no names and no identities/links').format(avatar.id)
continue
user = self._user_from_avatar(avatar)
self._fix_collisions(user, avatar)
db.session.add(user)
settings = self._settings_from_avatar(avatar)
user_settings.set_multi(user, settings)
# favorite users cannot be migrated here since the target user might not have been migrated yet
# XXX: adapt to new categories for 2.0
user.favorite_categories = set(filter(None, avatar.linkedTo['category']['favorite']))
db.session.flush()
print cformat('%{green}+++%{reset} '
'%{white!}{:6d}%{reset} %{cyan}{}%{reset} [%{blue!}{}%{reset}] '
'{{%{cyan!}{}%{reset}}}').format(user.id, user.full_name, user.email,
', '.join(user.secondary_emails))
# migrate API keys
self._migrate_api_keys(avatar, user)
# migrate identities of non-deleted avatars
if not user.is_deleted:
for old_identity in avatar.identities:
identity = None
username = convert_to_unicode(old_identity.login).strip().lower()
if not username:
print cformat("%{red!}!!!%{reset} "
"%{yellow!}Empty username: {}. Skipping identity.").format(
old_identity)
continue
provider = {
'LocalIdentity': 'indico',
'LDAPIdentity': self.ldap_provider_name
}.get(old_identity.__class__.__name__)
if provider is None:
print cformat("%{red!}!!!%{reset} "
"%{yellow!}Unsupported provider: {}. Skipping identity.").format(
old_identity.__class__.__name__)
continue
if (provider, username) in seen_identities:
print cformat("%{red!}!!!%{reset} "
"%{yellow!}Duplicate identity: {}, {}. Skipping.").format(provider, username)
continue
if provider == 'indico' and not self.ignore_local_accounts:
identity = Identity(provider=provider, identifier=username)
if not hasattr(old_identity, 'algorithm'): # plaintext password
if not old_identity.password:
# password is empty, skip identity
print cformat("%{red!}!!!%{reset} "
"%{yellow!}Identity '{}' has empty password. Skipping identity.").format(
old_identity.login)
continue
identity.password = old_identity.password
else:
assert old_identity.algorithm == 'bcrypt'
identity.password_hash = old_identity.password
elif provider == self.ldap_provider_name:
identity = Identity(provider=provider, identifier=username)
if identity:
print cformat('%{blue!}<->%{reset} %{yellow}{}%{reset}').format(identity)
user.identities.add(identity)
seen_identities.add((provider, username))
for merged_avatar in getattr(avatar, '_mergeFrom', ()):
if merged_avatar.id == avatar.id:
continue
merged = self._user_from_avatar(merged_avatar, is_deleted=True, merged_into_id=user.id)
print cformat('%{blue!}***%{reset} '
'%{white!}{:6d}%{reset} %{cyan}{}%{reset} [%{blue!}{}%{reset}] '
'{{%{cyan!}{}%{reset}}}').format(merged.id, merged.full_name, merged.email,
', '.join(merged.secondary_emails))
self._fix_collisions(merged, merged_avatar)
db.session.add(merged)
#.........这里部分代码省略.........