def team_register(): if request.method == "GET": return redirect(url_for('team_dashboard')) else: team_name = request.form["team_name"].strip() team_elig = "team_eligibility" in request.form affiliation = request.form["affiliation"].strip() try: if (Team.get(Team.name == team_name)): flash("The team name has been used.") return redirect(url_for('team_dashboard')) except Team.DoesNotExist: pass if len(team_name) > 50 or not team_name: flash("wrong team name format!") return redirect(url_for('team_dashboard')) if not affiliation or len(affiliation) > 100: affiliation = "No affiliation" team_leader = User.get(User.id == g.user.id) team = Team.create(name=team_name, eligible=team_elig, affiliation=affiliation, team_leader=team_leader) TeamMember.create(team=team,member=team_leader,member_confirmed=False) if not app.debug: UserAccess.create(user=g.user, ip=misc.get_ip(), time=datetime.now()) session["team_id"] = team.id app.logger.info(g.user.username+" register a team.") flash("The request has send to admin.") return redirect(url_for('team_dashboard'))
def register(): if not config.registration: if "admin" in session and session["admin"]: pass else: return "Registration is currently disabled. Email [email protected] to create an account." if request.method == "GET": return render_template("register.html") elif request.method == "POST": error, message = captcha.verify_captcha() if error: flash(message) return render_template("register.html") team_name = request.form["team_name"].strip() team_email = request.form["team_email"].strip() team_elig = "team_eligibility" in request.form affiliation = request.form["affiliation"].strip() if len(team_name) > 50 or not team_name: flash("You must have a team name!") return render_template("register.html") if not (team_email and "." in team_email and "@" in team_email): flash("You must have a valid team email!") return render_template("register.html") if not affiliation or len(affiliation) > 100: affiliation = "No affiliation" if not email.is_valid_email(team_email): flash("You're lying") return render_template("register.html") team_key = misc.generate_team_key() confirmation_key = misc.generate_confirmation_key() team = Team.create(name=team_name, email=team_email, eligible=team_elig, affiliation=affiliation, key=team_key, email_confirmation_key=confirmation_key) TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now()) email.send_confirmation_email(team_email, confirmation_key, team_key) session["team_id"] = team.id flash("Team created.") return redirect(url_for('dashboard'))
def login(): if request.method == "GET": return render_template("login.html") elif request.method == "POST": team_key = request.form["team_key"] try: team = Team.get(Team.key == team_key) TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now()) session["team_id"] = team.id flash("Login successful.") return redirect(url_for('dashboard')) except Team.DoesNotExist: flash("Couldn't find your team. Check your team key.", "error") return render_template("login.html")