예제 #1
0
파일: home.py 프로젝트: CNGL-repo/MTeval
def register():
    if current_user.is_authenticated():
        flash("You are already logged in, please log out to register a new team")
        return redirect(url_for("home.index"))
    form = RegisterForm(request.form)
    if request.method == "POST" and form.validate():
        #returns dict {success: Bool, reason: String}
        res = teamDB.addTeam( 
            form.teamname.data,
            form.email.data, 
            form.organisation.data,
            loginUtils.hashPassword(form.password.data)
        )
        if res["success"] == True:
            flash("Registration successful")
            return redirect(url_for("home.login"))
        else: 
            flash("Registration failed: " + res["reason"])
            return redirect(url_for("home.register"))

    return render_template("home/register.html", form = form)
예제 #2
0
파일: teams.py 프로젝트: CNGL-repo/MTeval
def editTeam(teamName):
    #only the current team may edit itself, or the admin may edit every team
    if current_user.isAdmin != True and current_user.teamName != teamName:
        flash("You don't have permission to edit this team")
        return redirect(url_for("home.index"))

    form = EditTeamForm(request.form)
    if request.method == "POST" and form.validate():
        teamDB.editTeam(
            teamName,
            form.teamname.data, 
            form.email.data,
            form.organisation.data,
            loginUtils.hashPassword(form.password.data)
        )
        flash("Updated team successfully")
        return redirect(url_for("home.index"))

    team = teamDB.getTeamByName(teamName)
    form.teamname.data = team["teamName"]
    form.email.data = team["email"]
    form.organisation.data = team["organisation"]
    return render_template("teams/editTeam.html", team=team, form=form)
예제 #3
0
파일: admin.py 프로젝트: CNGL-repo/MTeval
from itsdangerous import URLSafeTimedSerializer
from mteval.database import teamDB, compDB
from flask_mail import Mail, Message

admin = Blueprint("admin", __name__)

#mail initialisation
ts = URLSafeTimedSerializer(app.config["SECRET_KEY"]) 
mail = Mail(app)

#create an admin user if none exists
if teamDB.getAdmin() == None:
    teamDB.addTeam("admin", 
        "*****@*****.**",
        "admin", 
        loginUtils.hashPassword("password"), 
        isAdmin = True,
        emailVerified = True, 
        isActive = True)


#Route for admin panel, where the admin can do various tasks
@admin.route('/admin')
@login_required
def adminPanel():
    if current_user.isAdmin != True:
        flash("You are not an admin")
        return redirect(url_for("home.index"))

    #perhaps it might be better to get all teams once and then check for conditions in template?
    #rather than querying twice and passing a lot of redundant information