コード例 #1
0
ファイル: helpers_tests.py プロジェクト: penelopezone/nemesis
    def test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = ''
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        ps = last_email()
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired'
コード例 #2
0
ファイル: helpers_tests.py プロジェクト: samphippen/nemesis
    def test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = ''
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        ps = last_email()
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired'
コード例 #3
0
def create_pending_user(name = 'abc'):
    pu = PendingUser(name)
    pu.teacher_username = '******'
    pu.college = 'college-1'
    pu.team = 'team-ABC'
    pu.email = name + '@srobo.org'
    pu.verify_code = 'bibble'

    return pu
コード例 #4
0
ファイル: app.py プロジェクト: PeterJCLaw/nemesis
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
コード例 #5
0
def create_pending_user(name='abc'):
    pu = PendingUser(name)
    pu.teacher_username = '******'
    pu.college = 'college-1'
    pu.team = 'team-ABC'
    pu.email = name + '@srobo.org'
    pu.verify_code = 'bibble'

    return pu
コード例 #6
0
def test_update():
    test_creation()
    new_team = "team-XYZ"

    pu = PendingUser("abc")
    pu.team = new_team
    pu.save()

    pu = PendingUser("abc")
    assert pu.team == new_team
コード例 #7
0
def test_update():
    test_creation()
    new_team = 'team-XYZ'

    pu = PendingUser('abc')
    pu.team = new_team
    pu.save()

    pu = PendingUser('abc')
    assert pu.team == new_team
コード例 #8
0
ファイル: helpers_tests.py プロジェクト: samphippen/nemesis
    def test_is_email_used_pending_user(self):
        email = '*****@*****.**'
        pu = PendingUser('pu')
        pu.college = 'c'
        pu.team = 't'
        pu.teacher_username = '******'
        pu.verify_code = 'vc'
        pu.email = email
        pu.save()

        used = helpers.email_used(email)
        assert used == True
コード例 #9
0
ファイル: helpers_tests.py プロジェクト: penelopezone/nemesis
    def test_is_email_used_pending_user(self):
        email = '*****@*****.**'
        pu = PendingUser('pu')
        pu.college = 'c'
        pu.team = 't'
        pu.teacher_username = '******'
        pu.verify_code = 'vc'
        pu.email = email
        pu.save()

        used = helpers.email_used(email)
        assert used == True
コード例 #10
0
ファイル: app.py プロジェクト: Krenair/nemesis
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
コード例 #11
0
def test_properties():
    pu = PendingUser('abc')
    pu.teacher_username = '******'
    pu.college = 'college-1'
    pu.team = 'team-ABC'
    pu.email = '*****@*****.**'
    pu.verify_code = 'bibble'

    assert pu.username == 'abc'
    assert pu.teacher_username == 'jim'
    assert pu.college == 'college-1'
    assert pu.team == 'team-ABC'
    assert pu.email == '*****@*****.**'
    assert pu.verify_code == 'bibble'
    assert pu.age == timedelta()
コード例 #12
0
def test_properties():
    pu = PendingUser("abc")
    pu.teacher_username = "******"
    pu.college = "college-1"
    pu.team = "team-ABC"
    pu.email = "*****@*****.**"
    pu.verify_code = "bibble"

    assert pu.username == "abc"
    assert pu.teacher_username == "jim"
    assert pu.college == "college-1"
    assert pu.team == "team-ABC"
    assert pu.email == "*****@*****.**"
    assert pu.verify_code == "bibble"
    assert pu.age == timedelta()
コード例 #13
0
def test_str():
    pu = PendingUser('abc')
    pu.teacher_username = '******'
    pu.college = 'college-1'
    pu.team = 'team-ABC'
    pu.email = '*****@*****.**'
    pu.verify_code = 'bibble'

    as_str = str(pu)
    assert 'PendingUser' in as_str
    assert 'abc' in as_str
    assert 'jim' in as_str
    assert 'college-1' in as_str
    assert 'team-ABC' in as_str
    assert '*****@*****.**' in as_str
    assert 'bibble' in as_str
コード例 #14
0
def test_str():
    pu = PendingUser("abc")
    pu.teacher_username = "******"
    pu.college = "college-1"
    pu.team = "team-ABC"
    pu.email = "*****@*****.**"
    pu.verify_code = "bibble"

    as_str = str(pu)
    assert "PendingUser" in as_str
    assert "abc" in as_str
    assert "jim" in as_str
    assert "college-1" in as_str
    assert "team-ABC" in as_str
    assert "*****@*****.**" in as_str
    assert "bibble" in as_str
コード例 #15
0
def test_creation():
    pu = PendingUser('abc')
    pu.teacher_username = '******'
    pu.college = 'college-1'
    pu.team = 'team-ABC'
    pu.email = '*****@*****.**'
    pu.verify_code = 'bibble'

    pu.save()
    assert pu.in_db

    pu = PendingUser('abc')
    assert pu.in_db
    assert pu.username == 'abc'
    assert pu.teacher_username == 'jim'
    assert pu.college == 'college-1'
    assert pu.team == 'team-ABC'
    assert pu.email == '*****@*****.**'
    assert pu.verify_code == 'bibble'
    assert pu.age > timedelta()
    assert pu.age < timedelta(minutes=1)
コード例 #16
0
def test_creation():
    pu = PendingUser("abc")
    pu.teacher_username = "******"
    pu.college = "college-1"
    pu.team = "team-ABC"
    pu.email = "*****@*****.**"
    pu.verify_code = "bibble"

    pu.save()
    assert pu.in_db

    pu = PendingUser("abc")
    assert pu.in_db
    assert pu.username == "abc"
    assert pu.teacher_username == "jim"
    assert pu.college == "college-1"
    assert pu.team == "team-ABC"
    assert pu.email == "*****@*****.**"
    assert pu.verify_code == "bibble"
    assert pu.age > timedelta()
    assert pu.age < timedelta(minutes=1)
コード例 #17
0
ファイル: helpers_tests.py プロジェクト: PeterJCLaw/nemesis
    def test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = '' # match what libnemesis does when registering users
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        email = '*****@*****.**'
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = email
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        emails = last_n_emails(2)

        # Check we emailed the competitor
        ps = emails[0]
        toaddr = ps.toaddr
        assert email == toaddr

        vars = ps.template_vars
        assert first_name == vars['name']

        template = ps.template_name
        assert template == 'registration_expired'

        assert_load_template(template, vars)

        # Check we emailed the team leader
        ps = emails[1]
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired_team_leader'

        assert_load_template(template, vars)
コード例 #18
0
ファイル: app.py プロジェクト: penelopezone/nemesis
def register_user():
    ah = AuthHelper(request)

    if not ah.auth_will_succeed:
        return ah.auth_error_json, 403

    requesting_user = ah.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,
        '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
コード例 #19
0
ファイル: helpers_tests.py プロジェクト: PeterJCLaw/nemesis
    def test_clear_old_registrations(self):
        first_name = 'old'
        last_name = 'user'
        old_user = srusers.user('old')
        old_user.cname = first_name
        old_user.sname = last_name
        old_user.email = ''  # match what libnemesis does when registering users
        old_user.save()

        old_team_leader = User('teacher_coll1')

        pu = PendingUser('old')
        email = '*****@*****.**'
        pu.teacher_username = old_team_leader.username
        pu.college = 'college-1'
        pu.team = 'team-ABC'
        pu.email = email
        pu.verify_code = 'bibble-old'
        pu.save()

        self._make_old('registrations', 'old')

        pu = PendingUser('abc')
        pu.teacher_username = '******'
        pu.college = 'new-college-1'
        pu.team = 'team-NEW'
        pu.email = '*****@*****.**'
        pu.verify_code = 'bibble'
        pu.save()

        helpers.clear_old_registrations()

        pu = PendingUser('old')
        assert not pu.in_db

        pu = PendingUser('abc')
        assert pu.in_db

        emails = last_n_emails(2)

        # Check we emailed the competitor
        ps = emails[0]
        toaddr = ps.toaddr
        assert email == toaddr

        vars = ps.template_vars
        assert first_name == vars['name']

        template = ps.template_name
        assert template == 'registration_expired'

        assert_load_template(template, vars)

        # Check we emailed the team leader
        ps = emails[1]
        toaddr = ps.toaddr
        team_lead_email = old_team_leader.email
        assert toaddr == team_lead_email

        vars = ps.template_vars
        team_lead_first = old_team_leader.first_name
        assert team_lead_first == vars['name']
        assert first_name == vars['pu_first_name']
        assert last_name == vars['pu_last_name']

        template = ps.template_name
        assert template == 'registration_expired_team_leader'

        assert_load_template(template, vars)