Example #1
0
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)
Example #2
0
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