Exemplo n.º 1
0
    def test_is_email_valid(self):
        valids = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
        invalids = ['@srobo.org', '@b.cc', 'a@b', '[email protected]', 'a@b.', '[email protected]', 'a@cc', 'bacon', 'bacon.cc']
        for email in valids:
            is_valid = helpers.is_email_valid(email)
            assert is_valid, email

        for email in invalids:
            is_valid = helpers.is_email_valid(email)
            assert not is_valid, email
Exemplo n.º 2
0
    def test_is_email_valid(self):
        valids = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
        invalids = ['@srobo.org', '@b.cc', 'a@b', '[email protected]', 'a@b.', '[email protected]', 'a@cc', \
                    'bacon', 'bacon.cc', "\u5317\[email protected]"]
        for email in valids:
            is_valid = helpers.is_email_valid(email)
            assert is_valid, email

        for email in invalids:
            is_valid = helpers.is_email_valid(email)
            assert not is_valid, email
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def user_signup():
    username_input = cgi.escape(request.form['username'])
    pass_input = cgi.escape(request.form['password'])
    verify_pass_input = cgi.escape(request.form['verify'])
    email_input = cgi.escape(request.form['email'])
    is_user_blank = False
    is_user_invalid = False
    is_pass_blank = False
    pass_mismatch = False
    is_email_invalid = False

    is_user_blank = helpers.is_user_blank(username_input)
    is_user_invalid = helpers.is_user_invalid(username_input)
    is_pass_blank = helpers.is_pass_blank(pass_input)
    pass_mismatch = helpers.pass_mismatch(pass_input, verify_pass_input)
    is_email_invalid = helpers.is_email_valid(email_input)

    # Check to see if user input is valid, then mark global variable to trigger new form.
    if not is_user_blank and not is_user_invalid and not is_pass_blank and not pass_mismatch and not is_email_invalid:
        return redirect("/welcome?username={}".format(username_input))

    if is_user_blank:
        blank_user_error = "Username is required."
        if is_pass_blank:
            blank_pass_error = "That's an invalid password."
            if is_email_invalid:
                email_error = "That's an invalid email."
                return render_template('index.html',
                                       username=username_input,
                                       email=email_input,
                                       email_error=email_error,
                                       pass_error=blank_pass_error,
                                       user_error=blank_user_error)
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   user_error=blank_user_error,
                                   pass_error=blank_pass_error)
        elif pass_mismatch:
            verify_pass_error = "Password does not match. Please retype password exactly."
            if is_email_invalid:
                email_error = "That's an invalid email."
                return render_template('index.html',
                                       username=username_input,
                                       email=email_input,
                                       email_error=email_error,
                                       pass_error=verify_pass_error,
                                       user_error=blank_user_error)
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   user_error=blank_user_error,
                                   verify_pass_error=verify_pass_error)

        return render_template('index.html',
                               username=username_input,
                               email=email_input,
                               user_error=blank_user_error)
    elif is_user_invalid:
        invalid_user_error = "That's not a valid username."
        if is_pass_blank:
            blank_pass_error = "That's an invalid password."
            if is_email_invalid:
                email_error = "That's an invalid email."
                return render_template('index.html',
                                       username=username_input,
                                       email=email_input,
                                       email_error=email_error,
                                       user_error=invalid_user_error,
                                       pass_error=blank_pass_error)
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   user_error=invalid_user_error,
                                   pass_error=blank_pass_error)
        elif pass_mismatch:
            verify_pass_error = "Password does not match. Please retype password exactly."
            if is_email_invalid:
                email_error = "That's an invalid email."
                return render_template('index.html',
                                       username=username_input,
                                       email=email_input,
                                       email_error=email_error,
                                       pass_error=verify_pass_error,
                                       user_error=invalid_user_error)
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   user_error=blank_user_error,
                                   verify_pass_error=verify_pass_error)

        return render_template('index.html',
                               username=username_input,
                               email=email_input,
                               user_error=invalid_user_error)

    if is_pass_blank:
        blank_pass_error = "That's an invalid password."
        if is_email_invalid:
            email_error = "That's an invalid email."
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   email_error=email_error,
                                   pass_error=blank_pass_error)
        return render_template('index.html',
                               username=username_input,
                               email=email_input,
                               pass_error=blank_pass_error)
    elif pass_mismatch:
        verify_pass_error = "Password does not match. Please retype password exactly."
        if is_email_invalid:
            email_error = "That's an invalid email."
            return render_template('index.html',
                                   username=username_input,
                                   email=email_input,
                                   email_error=email_error,
                                   pass_error=verify_pass_error)
        return render_template('index.html',
                               username=username_input,
                               email=email_input,
                               verify_pass_error=verify_pass_error)

    if is_email_invalid:
        email_error = "That's an invalid email."
        return render_template('index.html',
                               username=username_input,
                               email=email_input,
                               email_error=email_error)

    return render_template('index.html',
                           username=username_input,
                           email=email_input)