當前位置: 首頁>>代碼示例>>Python>>正文


Python Identity.find方法代碼示例

本文整理匯總了Python中indico.modules.auth.Identity.find方法的典型用法代碼示例。如果您正苦於以下問題:Python Identity.find方法的具體用法?Python Identity.find怎麽用?Python Identity.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在indico.modules.auth.Identity的用法示例。


在下文中一共展示了Identity.find方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

# 需要導入模塊: from indico.modules.auth import Identity [as 別名]
# 或者: from indico.modules.auth.Identity import find [as 別名]
def create(grant_admin):
    """Creates a new user"""
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.query.filter(User.all_emails == email, ~User.is_deleted, ~User.is_pending).has_rows():
            break
        print(cformat('%{red}Email already exists'))
    first_name = click.prompt("First name").strip()
    last_name = click.prompt("Last name").strip()
    affiliation = click.prompt("Affiliation", '').strip()
    print()
    while True:
        username = click.prompt("Enter username").lower().strip()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        print(cformat('%{red}Username already exists'))
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    _print_user_info(user)

    if click.confirm(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        print(cformat("%{green}New {} created successfully with ID: %{green!}{}").format(user_type, user.id))
開發者ID:ThiefMaster,項目名稱:indico,代碼行數:36,代碼來源:user.py

示例2: user_create

# 需要導入模塊: from indico.modules.auth import Identity [as 別名]
# 或者: from indico.modules.auth.Identity import find [as 別名]
def user_create(grant_admin):
    """Creates new user"""
    update_session_options(db)
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.find(User.all_emails.contains(email), ~User.is_deleted, ~User.is_pending).count():
            break
        error('Email already exists')
    first_name = prompt("First name")
    last_name = prompt("Last name")
    affiliation = prompt("Affiliation", '')
    print()
    while True:
        username = prompt("Enter username").lower()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        error('Username already exists')
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    print_user_info(user)

    if prompt_bool(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        success("New {} created successfully with ID: {}".format(user_type, user.id))
開發者ID:OmeGak,項目名稱:indico,代碼行數:37,代碼來源:admin.py

示例3: validate_username

# 需要導入模塊: from indico.modules.auth import Identity [as 別名]
# 或者: from indico.modules.auth.Identity import find [as 別名]
 def validate_username(self, field):
     query = Identity.find(
         Identity.provider == "indico",
         Identity.identifier == field.data,
         Identity.identifier != self.identity.identifier,
     )
     if query.count():
         raise ValidationError(_("This username is already in use."))
開發者ID:OmeGak,項目名稱:indico,代碼行數:10,代碼來源:forms.py

示例4: _check_existing_username

# 需要導入模塊: from indico.modules.auth import Identity [as 別名]
# 或者: from indico.modules.auth.Identity import find [as 別名]
def _check_existing_username(form, field):
    if Identity.find(provider='indico', identifier=field.data).count():
        raise ValidationError(_('This username is already in use.'))
開發者ID:fph,項目名稱:indico,代碼行數:5,代碼來源:forms.py


注:本文中的indico.modules.auth.Identity.find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。