moved js validation

master
James Sigurðarson 2016-07-12 19:17:24 +00:00
parent 39a5dedacf
commit 632f1b2bd5
4 changed files with 43 additions and 15 deletions

18
app.py
View File

@ -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

View File

@ -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");
});
}
});

View File

@ -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);
}
});
});
</script>
{% endblock %}

View File

@ -135,4 +135,19 @@
{% if first_login %}
<script>$("#firstlogin").openModal();</script>
{% endif %}
<script>
$(function(){
$("#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);
}
});
});
</script>
{% endblock %}