当前位置: 首页>>代码示例>>Python>>正文


Python User.name_used方法代码示例

本文整理汇总了Python中libnemesis.User.name_used方法的典型用法代码示例。如果您正苦于以下问题:Python User.name_used方法的具体用法?Python User.name_used怎么用?Python User.name_used使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libnemesis.User的用法示例。


在下文中一共展示了User.name_used方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register_user

# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import name_used [as 别名]
def register_user(requesting_user):
    if not requesting_user.can_register_users:
        return json.dumps({"error":"YOU_CANT_REGISTER_USERS"}), 403

    teacher_username = requesting_user.username
    college_group    = request.form["college"].strip()
    first_name       = request.form["first_name"].strip()
    last_name        = request.form["last_name"].strip()
    email            = request.form["email"].strip()
    team             = request.form["team"].strip()

    if College(college_group) not in requesting_user.colleges:
        return json.dumps({"error":"BAD_COLLEGE"}), 403

    if team not in [t.name for t in College(college_group).teams]:
        return json.dumps({"error":"BAD_TEAM"}), 403

    if not helpers.is_email_valid(email):
        return json.dumps({"error":"BAD_EMAIL"}), 403

    if not helpers.is_name_valid(first_name):
        return json.dumps({"error":"BAD_FIRST_NAME"}), 403

    if not helpers.is_name_valid(last_name):
        return json.dumps({"error":"BAD_LAST_NAME"}), 403

    if User.name_used(first_name, last_name) or helpers.email_used(email):
        return json.dumps({"error":"DETAILS_ALREADY_USED"}), 403

    u = User.create_new_user(requesting_user, college_group, first_name, last_name)
    verify_code = helpers.create_verify_code(u.username, email)

    pu = PendingUser(u.username)
    pu.teacher_username = teacher_username
    pu.college = college_group
    pu.email = email
    pu.team = team
    pu.verify_code = verify_code
    pu.save()

    log_action('registering user', pu)

    url = url_for('activate_account', username=u.username, code=verify_code, _external=True)
    pu.send_welcome_email(first_name, url)

    rqu_email_vars = { 'name': requesting_user.first_name,
            'activation_days': ACTIVATION_DAYS,
              'pu_first_name': first_name,
               'pu_last_name': last_name,
                'pu_username': pu.username,
                 'pu_college': College(pu.college).name,
                   'pu_email': pu.email,
                    'pu_team': pu.team
                      }
    mailer.email_template(requesting_user.email, 'user_requested', rqu_email_vars)

    return "{}", 202
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:59,代码来源:app.py

示例2: register_user

# 需要导入模块: from libnemesis import User [as 别名]
# 或者: from libnemesis.User import name_used [as 别名]
def register_user():
    ah = AuthHelper(request)
    if ah.auth_will_succeed:
        requesting_user = ah.user
        if requesting_user.can_register_users:
            teacher_username = requesting_user.username
            college_group    = request.form["college"].strip()
            first_name       = request.form["first_name"].strip()
            last_name        = request.form["last_name"].strip()
            email            = request.form["email"].strip()
            team             = request.form["team"].strip()

            if College(college_group) not in requesting_user.colleges:
                return json.dumps({"error":"BAD_COLLEGE"}), 403

            if team not in [t.name for t in College(college_group).teams]:
                return json.dumps({"error":"BAD_TEAM"}), 403

            if User.name_used(first_name, last_name) or helpers.email_used(email):
                return json.dumps({"error":"DETAILS_ALREADY_USED"}), 403

            u = User.create_new_user(requesting_user, college_group, first_name, last_name)
            verify_code = helpers.create_verify_code(u.username, email)

            pu = PendingUser(u.username)
            pu.teacher_username = teacher_username
            pu.college = college_group
            pu.email = email
            pu.team = team
            pu.verify_code = verify_code
            pu.save()

            url = url_for('activate_account', username=u.username, code=verify_code, _external=True)
            pu.send_welcome_email(first_name, url)

            rqu_email_vars = { 'name': requesting_user.first_name,
                      'pu_first_name': first_name,
                       'pu_last_name': last_name,
                        'pu_username': pu.username,
                         'pu_college': College(pu.college).name,
                           'pu_email': pu.email,
                            'pu_team': pu.team
                              }
            mailer.email_template(requesting_user.email, 'user_requested', rqu_email_vars)

            return "{}", 202
        else:
            return json.dumps({"error":"YOU_CANT_REGISTER_USERS"}),403
    else:
        return ah.auth_error_json, 403
开发者ID:Krenair,项目名称:nemesis,代码行数:52,代码来源:app.py


注:本文中的libnemesis.User.name_used方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。