diff --git a/app.py b/app.py index 84fd7be..b766704 100644 --- a/app.py +++ b/app.py @@ -170,6 +170,10 @@ def register(): flash("Invalid Background") return render_template("register.html") + if (not gender == "") and (not gender in ["M", "F"]): + flash("Invalid gender") + return render_template("register.html") + confirmation_key = misc.generate_confirmation_key() team=None @@ -249,8 +253,12 @@ def user_dashboard(): background = request.form["background"].strip() country = request.form["country"].strip() - tshirt_size = request.form["tshirt_size"].strip() - gender = request.form["gender"].strip() + tshirt_size = "" + gender = "" + if "tshirt_size" in request.form.keys(): + tshirt_size = request.form["tshirt_size"].strip() + if "gender" in request.form.keys(): + gender = request.form["gender"].strip() if len(username) > 50 or not username: flash("You must have a username!") @@ -271,7 +279,7 @@ def user_dashboard(): flash("You're lying") return redirect(url_for('user_dashboard')) - if not tshirt_size in select.TShirts: + if (not tshirt_size == "") and (not tshirt_size in select.TShirts): flash("Invalid T-shirt size") return redirect(url_for('user_dashboard')) @@ -283,6 +291,10 @@ def user_dashboard(): flash("Invalid Background") return redirect(url_for('user_dashboard')) + if (not gender == "") and (not gender in ["M", "F"]): + flash("Invalid gender") + return redirect(url_for('user_dashboard')) + email_changed = (user_email != g.user.email) g.user.username = username diff --git a/static/js/main.js b/static/js/main.js index 9436ea1..265381f 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,15 +1,3 @@ $( document ).ready(function() { $('select').material_select(); - - if($("#country").length) - { - $("#country").change(function(e) { - if($("#country").val() == "ISL") - $("#prize-info").show("slow"); - else - $("#prize-info").hide("slow"); - - }); - } - }); diff --git a/templates/register.html b/templates/register.html index 86f0362..2869183 100644 --- a/templates/register.html +++ b/templates/register.html @@ -118,6 +118,19 @@ $(function(){ $("#join-team #team_key").prop('required', true); $("#join-team #join_team").attr('val', "1"); }); + + $("#country").change(function(e) { + if($("#country").val() == "ISL"){ + $("#prize-info").show("slow"); + $("#tshirt_size").prop('required', true); + $("#male").prop('required', true); + } else { + $("#prize-info").hide("slow"); + $("#tshirt_size").prop('required', false); + $("#male").prop('required', false); + } + }); + }); {% endblock %} diff --git a/templates/user.html b/templates/user.html index df76ae9..a975106 100644 --- a/templates/user.html +++ b/templates/user.html @@ -135,4 +135,19 @@ {% if first_login %} {% endif %} + {% endblock %}