Example #1
0
def user_render(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        users = database.get_users()
        if request.method == "POST":
            email = request.form["email"]
            password = request.form["password"]
            password2 = request.form["password-two"]
            new_access = request.form["access"]
            name = request.form["name"]
            location = request.form["location"]
            # Change this to create a user if authentic email
            if password != password2:
                return render_template("users.html", users=users, access=access, error="Passwords for " + email + " do not match.")

            if database.user_exists(email):
                return render_template("users.html", users=users, access=access, error="User: "******" already exists.")
            
            database.create_user(email, password, name, new_access, location)

            token = security.generate_confirmation_token(email)
            confirm_url = url_for("confirm", token=token, _external=True)
            html = render_template("account.html", confirm_url=confirm_url, access = new_access, password=password)
            subject = "Please confirm your email"
            send_email(email, subject, html)
            print("CONFIRM: ", confirm_url)
            print("EMAIL: ", email)
            return render_template("users.html", users=users, access=access, error="An authentication email has been send to: " + email)
        else:
            return render_template("users.html", users=users, access=access)
Example #2
0
def fetch_ammouncements(access, group):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")

    section = None if group == "public" else group
    announcements = database.get_announcements(group=section)
    return render_template("announcer.html", announcements=announcements, access=access)
Example #3
0
def edit_all(access, editing):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))

    return render_template("editing.html", options=True, access=access, 
            editing=editing, groups=config.STUDENT_PAGE_DICT)
Example #4
0
def remove_announcement(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))

    removal = request.form["announcement_id"]

    database.remove_announcement(removal=removal)

    return redirect(url_for("edit_all", access=session["access"], editing="announce"))
Example #5
0
def load_templates(access, location, filename):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    try:
        if database.is_student(access):
            git_link = database.get_git_link(session["email"])
        else:
            git_link = "/"
        location = database.get_location(session["email"])
        return render_template(filename, access=access, github_link=git_link, location = location)
    except jinja2.exceptions.TemplateNotFound as e:
        return render_template("error.html", error="Page not found.")
Example #6
0
def users_graduate(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        grads = request.form["grads"]
        database.graduate_students(group=grads)

        users = database.get_users()

        return render_template("users.html", users=users, access=access, error=grads + " have been graduated.")
Example #7
0
def delete_material(access, editing, assignment):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        name = request.form["name"]
        link = request.form["link"]

        if not database.valid_edit(editing, assignment):
            return render_template("error.html", error="Invalid deletion attempt.")

        database.remove_lecture(link=link, group=editing, name=name)
        return redirect(url_for("edits", access=access, editing=editing, assignment=assignment))
Example #8
0
def make_announcement(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))

    name = request.form["name"]
    text = request.form["statement"]
    viewable = request.form["view"]
    date = datetime.datetime.now()
    poster = database.get_name(session["email"])

    database.make_announcement(date=date, name=name, text=text, poster=poster, group=viewable)
    return redirect(url_for("edit_all", access=access, editing="announce"))
Example #9
0
def user_remove(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        email = request.form["email"]
        users = database.get_users()

        if not database.user_exists(email):
            return render_template("users.html", users=users, access=access, error="User: "******" does not exist.")
        
        database.remove_user(email=email)
        users = database.get_users()
        return render_template("users.html", users=users, access=access, error=email + " has been removed permanantly.")
Example #10
0
def edits(access, editing, assignment):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))


    if not database.valid_edit(editing, assignment):
        return render_template("error.html", error="Invalid edit attempt.")

    existing = database.get_existing_lectures(editing, assignment, location=None)

    return render_template("editing.html", options=False, existing=existing, 
                access=session["access"], editing=editing, assignment=assignment, 
                assign_name=config.STUDENT_PAGE_DICT[assignment])
Example #11
0
def access_material(access, location, assignment):
    if not database.valid_access(access) or assignment not in config.STUDENT_PAGE_LINKS or not database.valid_location(location):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    elif location != session["location"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        existing = database.get_existing_lectures(access, assignment, location)
        location = database.get_location(session["email"])

        return render_template("lectures.html", access=access, 
            lectures=existing,
            github_link=session["gitlink"],
            header=config.STUDENT_PAGE_DICT[assignment], 
            location=location)
Example #12
0
def login_home(access):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))

    if database.is_admin(access):
        return render_template("admin_home.html", access=access)
    elif database.is_student(access):
        announcements = database.get_announcements(access)
        location = database.get_location(session["email"])
        return render_template("student_home.html", access=access, 
                location=location,
                github_link=session["gitlink"], announcements=announcements)
    else:
        return redirect(url_for("unauthorized"))
Example #13
0
def add_material(access, editing, assignment):
    if not database.valid_access(access):
        return render_template("error.html", error="Page not found.")
    elif access != session["access"] and not database.is_admin(session["access"]):
        return redirect(url_for("unauthorized"))
    else:
        name = request.form["name"]
        link = request.form["link"]
        lec_type = request.form["lec_type"]
        location = request.form["location"]

        if not database.valid_edit(editing, assignment):
            return render_template("error.html", error="Invalid upload.")

        if not database.embedable_link(link):
            return render_template("error.html", error="Link not embeddable. Did you publish to the web?")

        database.add_lecture(link=link, group=editing, name=name, assign_type=assignment, 
                            lec_type=lec_type, location=location)
        return redirect(url_for("edits", access=access, editing=editing, assignment=assignment))