示例#1
0
def student_id():
    github = github_username()
    if request.method == "GET":
        return render_template("onboarding/student_id.html", github=github)
    try:
        mailer_job = None
        github_job = None
        with DbCursor() as c:
            user = get_user_by_github(c, github)
            if user:
                return redirect(url_for("dashboard.index"))
            student_id = request.form.get("f_student_id")
            if not student_id:
                fail_validation("Student ID is required")
            user = get_user_by_student_id(c, student_id)
            if not user:
                fail_validation("Student not found with that student ID")
            user_id, name, _, login, old_github, email = user
            if old_github:
                fail_validation(
                    "Another GitHub account has been associated with that student "
                    "ID already.")
            if not name:
                fail_validation(
                    "There is no name associated with this account. (Contact your TA?)"
                )
            if not login:
                fail_validation(
                    "There is no login associated with this account. (Contact your "
                    "TA?)")
            if not email:
                fail_validation(
                    "There is no email associated with this account. (Contact your "
                    "TA?)")
            c.execute('''UPDATE users SET github = ? WHERE sid = ?''',
                      [github, student_id])
            if not config.github_read_only_mode:
                github_job = repomanager_queue.create(c, "assign_repo",
                                                      (login, [github]))
            if config.mailer_enabled:
                if config.inst_account_enabled:
                    attachments = [("pdf", get_inst_account_form_path(login))]
                else:
                    attachments = []
                email_payload = create_email(
                    "onboarding_confirm",
                    email,
                    "%s Autograder Registration" % config.course_number,
                    _attachments=attachments,
                    name=name,
                    login=login,
                    inst_account_enabled=config.inst_account_enabled)
                mailer_job = mailer_queue.create(c, "send", email_payload)
        if config.mailer_enabled and mailer_job:
            mailer_queue.enqueue(mailer_job)
        if not config.github_read_only_mode and github_job:
            repomanager_queue.enqueue(github_job)
        return redirect(url_for(_get_next_step("onboarding.student_id")))
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.student_id"), e)
示例#2
0
文件: validation.py 项目: aykamko/ob2
def _validate_account_forms(c):
    if config.inst_account_enabled:
        c.execute("SELECT login FROM users WHERE login IS NOT NULL")
        logins = [login for login, in c.fetchall()]
        for login in logins:
            expected_path = get_inst_account_form_path(login)
            assert exists(expected_path), ("Cannot find account form for %s at %s" %
                                           (config.course_login_format % login, expected_path))
示例#3
0
def _validate_account_forms(c):
    if config.inst_account_enabled:
        c.execute("SELECT login FROM users WHERE login IS NOT NULL")
        logins = [login for login, in c.fetchall()]
        for login in logins:
            expected_path = get_inst_account_form_path(login)
            assert exists(expected_path), (
                "Cannot find account form for %s at %s" %
                (config.course_login_format % login, expected_path))
示例#4
0
文件: __init__.py 项目: aykamko/ob2
def student_id():
    github = github_username()
    if request.method == "GET":
        return render_template("onboarding/student_id.html",
                               github=github)
    try:
        mailer_job = None
        github_job = None
        with DbCursor() as c:
            user = get_user_by_github(c, github)
            if user:
                return redirect(url_for("dashboard.index"))
            student_id = request.form.get("f_student_id")
            if not student_id:
                fail_validation("Student ID is required")
            user = get_user_by_student_id(c, student_id)
            if not user:
                fail_validation("Student not found with that student ID")
            user_id, name, _, login, old_github, email = user
            if old_github:
                fail_validation("Another GitHub account has been associated with that student "
                                "ID already.")
            if not name:
                fail_validation("There is no name associated with this account. (Contact your TA?)")
            if not login:
                fail_validation("There is no login associated with this account. (Contact your "
                                "TA?)")
            if not email:
                fail_validation("There is no email associated with this account. (Contact your "
                                "TA?)")
            c.execute('''UPDATE users SET github = ? WHERE sid = ?''',
                      [github, student_id])
            if not config.github_read_only_mode:
                github_job = repomanager_queue.create(c, "assign_repo", (login, [github]))
            if config.mailer_enabled:
                if config.inst_account_enabled:
                    attachments = [("pdf", get_inst_account_form_path(login))]
                else:
                    attachments = []
                email_payload = create_email("onboarding_confirm", email,
                                             "%s Autograder Registration" % config.course_number,
                                             _attachments=attachments, name=name, login=login,
                                             inst_account_enabled=config.inst_account_enabled)
                mailer_job = mailer_queue.create(c, "send", email_payload)
        if config.mailer_enabled and mailer_job:
            mailer_queue.enqueue(mailer_job)
        if not config.github_read_only_mode and github_job:
            repomanager_queue.enqueue(github_job)
        return redirect(url_for(_get_next_step("onboarding.student_id")))
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.student_id"), e)