Exemple #1
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)
Exemple #2
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)
Exemple #3
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"))
Exemple #4
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)
Exemple #5
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"))
Exemple #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.")
Exemple #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))
Exemple #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"))
Exemple #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.")
Exemple #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])
Exemple #11
0
    def login(self):
        if self.verify_user():
            manager.LOGGED_IN = self.username_box.text
            manager.ADMIN = database.is_admin(
                self.username_box.text) or self.username_box.text == "admin"
            manager.sm.current = "menu"
            manager.menu.draw_menu()
            self.username_box.text = ""
            self.password_box.text = ""
            if manager.admin_pw == 'admin' and manager.ADMIN:
                self.popups.change_admin_prompt(None)

            if self.err_present:
                self.layout.remove_widget(self.err_label)
                self.err_present = False
        else:
            if not self.err_present:
                self.err_present = True
                self.layout.add_widget(self.err_label)
Exemple #12
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))