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


Python libnemesis.User类代码示例

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


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

示例1: verify_email

def verify_email(username, code):
    """
    Verifies to the system that an email address exists, and assigns it to a user.
    Expected to be used only by users clicking links in email-verfication emails.
    Not part of the documented API.
    """

    change_request = PendingEmail(username)

    if not change_request.in_db:
        return "No such change request", 404

    if change_request.age > timedelta(days = 2):
        return "Request not valid", 410

    if change_request.verify_code != code:
        return "Invalid verification code", 403

    log_action('changing email', user = username, new_email = change_request.new_email)

    u = User(change_request.username)
    u.set_email(change_request.new_email)
    u.save()

    return "Email address successfully changed", 200
开发者ID:samphippen,项目名称:nemesis,代码行数:25,代码来源:app.py

示例2: verify_email

def verify_email(username, code):
    """
    Verifies to the system that an email address exists, and assigns it to a user.
    Expected to be used only by users clicking links in email-verfication emails.
    Not part of the documented API.
    """

    change_request = PendingEmail(username)

    if not change_request.in_db:
        return "No such change request", 404, PLAINTEXT_HEADER

    email_change_days = config.config.getint('nemesis', 'email_change_days')
    max_age = timedelta(days = email_change_days)

    if change_request.age > max_age:
        return "Request not valid", 410, PLAINTEXT_HEADER

    if change_request.verify_code != code:
        return "Invalid verification code", 403, PLAINTEXT_HEADER

    log_action('changing email', user = username, new_email = change_request.new_email)

    u = User(change_request.username)
    u.set_email(change_request.new_email)
    u.save()

    return "Email address successfully changed", 200, PLAINTEXT_HEADER
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:28,代码来源:app.py

示例3: register_user

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,代码行数:57,代码来源:app.py

示例4: form_helper

def form_helper(rq_user, rq_pass, new_fname, new_lname):
    new_email = "[email protected]"
    params = {"username":rq_user,
              "password":rq_pass,
              "first_name":new_fname,
              "last_name":new_lname,
              "email":new_email,
              "team":"team-ABC",
              "college":"college-1"}

    r,data = test_helpers.server_post("/registrations", params)
    status = r.status
    assert status == 202, data

    created = User.create_user('1_rt1')
    assert created.email == ''

    pending = PendingUser('1_rt1')
    assert pending.email == "[email protected]"
    assert pending.team == "team-ABC"
    assert pending.college == "college-1"

    email_datas = test_helpers.last_n_emails(2)

    student_ps = email_datas[0]
    template = student_ps.template_name
    assert template == 'new_user'
    to = student_ps.toaddr
    assert to == new_email
    vars = student_ps.template_vars
    assert new_fname == vars['name']
    vcode = pending.verify_code
    assert vcode in vars['activation_url']

    test_helpers.assert_load_template(template, vars)

    teacher = User.create_user(rq_user)

    teacher_ps = email_datas[1]
    template = teacher_ps.template_name
    assert template == 'user_requested'
    to = teacher_ps.toaddr
    assert to == teacher.email
    vars = teacher_ps.template_vars
    assert new_fname == vars['pu_first_name']
    assert new_lname == vars['pu_last_name']
    assert new_email == vars['pu_email']
    assert '1_rt1' == vars['pu_username']
    assert 'team-ABC' == vars['pu_team']
    assert 'college the first' == vars['pu_college']

    vars_str = teacher_ps.template_vars_json
    assert vcode not in vars_str, "Should not contain the verification code."

    test_helpers.assert_load_template(template, vars)
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:55,代码来源:test_registrations.py

示例5: test_post_sets_own_password_and_name

def test_post_sets_own_password_and_name():
    old_password = "blueshirt"
    new_password = 'bacon'
    old_first = "Blue"
    old_last  = "Shirt"

    params = {"username":"blueshirt",
              "password":old_password,
              "new_password":new_password,
              "new_first_name":'new_first',
              "new_last_name":'new_last',
              }

    r,data = test_helpers.server_post("/user/blueshirt", params)
    assert r.status == 200
    assert User("blueshirt")._user.bind(new_password)

    u = User("blueshirt")
    first = u.first_name
    last = u.last_name
    u.set_password(old_password)
    u.set_first_name(old_first)
    u.set_last_name(old_last)
    u.save()

    assert first == 'new_first'
    assert last == 'new_last'
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:27,代码来源:test_users_post.py

示例6: clear_old_registrations

def clear_old_registrations():
    for pu in PendingUser.ListAll():
        # deliberately a larger delta than we restrict against to avoid
        # accidentally removing vaild entries
        if pu.age > timedelta(days = 3):
            pu.delete()
            expired = User(pu.username)
            expired.delete()

            team_leader = User(pu.teacher_username)
            inform_team_lead_registration_expired(team_leader, expired)
开发者ID:Krenair,项目名称:nemesis,代码行数:11,代码来源:helpers.py

示例7: test_registration_rq_from_blueshirt

def test_registration_rq_from_blueshirt():
    new_email = "[email protected]"
    params = {
        "username": "blueshirt",
        "password": "blueshirt",
        "first_name": NEW_USER_FNAME,
        "last_name": NEW_USER_LNAME,
        "email": new_email,
        "team": "team-ABC",
        "college": "college-1",
    }

    r, data = test_helpers.server_post("/registrations", params)
    status = r.status
    assert status == 202, data

    created = User.create_user("1_rt1")
    assert created.email == ""

    pending = PendingUser("1_rt1")
    assert pending.email == "[email protected]"
    assert pending.team == "team-ABC"
    assert pending.college == "college-1"

    email_datas = test_helpers.last_n_emails(2)

    student_ps = email_datas[0]
    template = student_ps.template_name
    assert template == "new_user"
    to = student_ps.toaddr
    assert to == new_email
    vars = student_ps.template_vars
    assert NEW_USER_FNAME == vars["name"]
    vcode = pending.verify_code
    assert vcode in vars["activation_url"]

    teacher = User.create_user("blueshirt")

    teacher_ps = email_datas[1]
    template = teacher_ps.template_name
    assert template == "user_requested"
    to = teacher_ps.toaddr
    assert to == teacher.email
    vars = teacher_ps.template_vars
    assert NEW_USER_FNAME == vars["pu_first_name"]
    assert NEW_USER_LNAME == vars["pu_last_name"]
    assert new_email == vars["pu_email"]
    assert "1_rt1" == vars["pu_username"]
    assert "team-ABC" == vars["pu_team"]
    assert "college the first" == vars["pu_college"]

    vars_str = teacher_ps.template_vars_json
    assert vcode not in vars_str, "Should not contain the verification code."
开发者ID:Krenair,项目名称:nemesis,代码行数:53,代码来源:test_registrations.py

示例8: set_user_details

def set_user_details(requesting_user, userid):
    user_to_update = User.create_user(userid)
    can_admin = requesting_user.can_administrate(user_to_update)

    if request.form.get("media_consent") == 'true' and requesting_user.can_record_media_consent:
        if not user_to_update.has_media_consent:
            user_to_update.got_media_consent()
            notify_ticket_available(user_to_update)
            user_to_update.save()

        if not can_admin:
            return '{}', 200

    elif not can_admin:
        return AUTHORIZATION_DENIED

    assert can_admin

    user_to_update = User.create_user(userid)
    if request.form.has_key("new_email") and not requesting_user.is_blueshirt:
        new_email = request.form["new_email"]
        request_new_email(user_to_update, new_email)
    # Students aren't allowed to update their own names
    # at this point, if the requesting_user is valid, we know it's a self-edit
    if not requesting_user.is_student:
        fname = request.form.get("new_first_name")
        if fname:
            user_to_update.set_first_name(fname)
        lname = request.form.get("new_last_name")
        if lname:
            user_to_update.set_last_name(lname)
    if request.form.has_key("new_team"):
        team = request.form["new_team"]
        if (not user_to_update.is_blueshirt) and requesting_user.manages_team(team):
            user_to_update.set_team(team)
    if request.form.has_key("new_type") and requesting_user.is_teacher and user_to_update != requesting_user:
        if request.form["new_type"] == 'student':
            user_to_update.make_student()
        elif request.form["new_type"] == 'team-leader':
            user_to_update.make_teacher()
    if request.form.get("withdrawn") == 'true' and not user_to_update.has_withdrawn \
        and requesting_user.can_withdraw(user_to_update):
        user_to_update.withdraw()

    user_to_update.save()

    # Do this separately and last because it makes an immediate change
    # to the underlying database, rather than waiting for save().
    if request.form.has_key("new_password"):
        user_to_update.set_password(request.form["new_password"])

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

示例9: register_user

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,代码行数:50,代码来源:app.py

示例10: test_team_leader_can_become_student

def test_team_leader_can_become_student():
    # We need to test against another teacher, because team leaders demoting themselves is not allowed
    u = User("student_coll1_1")
    u.make_teacher()
    u.save()

    params = {"username": "teacher_coll1",
              "password": "facebees",
              "new_type": "student",
              }

    r,data = test_helpers.server_post("/user/student_coll1_1", params)
    assert r.status == 200

    assert not User("student_coll1_1").is_teacher
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:15,代码来源:test_users_post.py

示例11: test_post_sets_others_password

def test_post_sets_others_password():
    old_password = "cows"

    params = {"username":"blueshirt",
              "password":"blueshirt",
              "new_password":"com",
              }

    r,data = test_helpers.server_post("/user/student_coll1_1", params)
    assert r.status == 200
    assert User("student_coll1_1")._user.bind("com")

    u = User("student_coll1_1")
    u.set_password(old_password)
    u.save()
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:15,代码来源:test_users_post.py

示例12: test_registration_email_in_use

def test_registration_email_in_use():
    params = {
        "username": "teacher_coll1",
        "password": "facebees",
        "first_name": NEW_USER_FNAME,
        "last_name": NEW_USER_LNAME,
        "email": "[email protected]",  # student_coll2_2
        "team": "team-ABC",
        "college": "college-1",
    }

    r, data = test_helpers.server_post("/registrations", params)

    assert r.status == 403
    assert "DETAILS_ALREADY_USED" in data
    assert len(test_helpers.get_registrations()) == 0

    try:
        created = User.create_user("1_rt1")
        assert False, "Should not have created user"
    except:
        pass

    pending = PendingUser("1_rt1")
    assert not pending.in_db

    test_helpers.assert_no_emails()
开发者ID:Krenair,项目名称:nemesis,代码行数:27,代码来源:test_registrations.py

示例13: test_post_sets_own_password

def test_post_sets_own_password():
    old_password = "blueshirt"
    new_password = 'bacon'

    params = {"username":"blueshirt",
              "password":old_password,
              "new_password":new_password,
              }

    r,data = test_helpers.server_post("/user/blueshirt", params)
    assert r.status == 200
    assert User("blueshirt")._user.bind(new_password)

    u = User("blueshirt")
    u.set_password(old_password)
    u.save()
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:16,代码来源:test_users_post.py

示例14: test_registration_name_in_use

def test_registration_name_in_use():
    params = {"username":"teacher_coll1",
              "password":"facebees",
              "first_name":'student2', # student_coll1_2
              "last_name":'student',
              "email":"[email protected]",
              "team":"team-ABC",
              "college":"college-1"}

    r,data = test_helpers.server_post("/registrations", params)

    status = r.status
    assert status == 403, data
    assert 'DETAILS_ALREADY_USED' in data
    assert len(test_helpers.get_registrations()) == 0

    try:
        created = User.create_user('1_ss1')
        assert False, "Should not have created user"
    except:
        pass

    pending = PendingUser('1_ss1')
    assert not pending.in_db

    test_helpers.assert_no_emails()
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:26,代码来源:test_registrations.py

示例15: test_registration_bad_frist_name

def test_registration_bad_frist_name():
    params = {"username":"teacher_coll1",
              "password":"facebees",
              "first_name":NEW_USER_FNAME,
              "last_name":'2'+NEW_USER_LNAME,
              "email":"[email protected]",
              "team":"team-ABC",
              "college":"college-1"}

    r,data = test_helpers.server_post("/registrations", params)

    assert r.status == 403
    assert 'BAD_LAST_NAME' in data
    assert len(test_helpers.get_registrations()) == 0

    try:
        created = User.create_user('1_rt1')
        assert False, "Should not have created user"
    except:
        pass

    pending = PendingUser('1_rt1')
    assert not pending.in_db

    test_helpers.assert_no_emails()
开发者ID:PeterJCLaw,项目名称:nemesis,代码行数:25,代码来源:test_registrations.py


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