Skip to content

Commit

Permalink
Added 'check on teams' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Oct 20, 2015
1 parent c57a06a commit 86dd39f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
33 changes: 32 additions & 1 deletion huntserver/static/huntserver/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $(document).ready(function(){
}else if(html == "fail-full"){
alert("Team is already full, contact team leader or staff.")
}else{
$("#stage2").fadeOut(500, function(){$("#stage3").fadeIn(500);});
$("#stage2").fadeOut(500, function(){$("#stage3").fadeIn(500);});
}
},
error: function (jXHR, textStatus, errorThrown) {
Expand All @@ -82,6 +82,37 @@ $(document).ready(function(){
return false;
});

// Stage2-3 Proccessing
$('#teamInfoForm').on('submit', function (e) {
if($("#teamInfoForm select").val() == ""){
alert("Please pick a team.");
return false;
}
e.preventDefault();
$.ajax({
url : $(this).attr('action') || window.location.pathname,
type: "POST",
data: $("#teamInfoForm").serialize() + "&data=True",
success: function(html){
if(html == "fail-password"){
alert("Incorrect password");
}else{
$("#member-table").html("")
members = JSON.parse(html);
trHTML = ""
$.each(members, function (i, item) {
trHTML += '<tr><td>' + item.first_name + '</td><td>' + item.last_name + '</td><td>' + item.email + '</td></tr>';
});
$('#member-table').append(trHTML);
}
},
error: function (jXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
return false;
});

// Stage3 proccessing
$('#individualForm').on('submit', function (e) {
if(stage2Selection == 1){
Expand Down
41 changes: 37 additions & 4 deletions huntserver/templates/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="title">Registration</h1>
Join an existing team.
</div>
<div class="reg_choice" data-id="3">
Modify an existing registration.
Check on an existing team registration.
</div>
</div>
<div style="display:none;" id="stage2">
Expand Down Expand Up @@ -98,9 +98,42 @@ <h1 class="title">Registration</h1>
</form>
</div>
<div id="stage2-3" style="display:none;">
We do not currently support modifying registrations (soon though!)
</br>
<input type="button" class="back2to1" value="Back" />
<form action="/registration/" id="teamInfoForm">
{% csrf_token %}
<table>
<tr>
<td>Team name: </td>
<td>
<select name="team_name">
<option value=""></option>
{% for team in teams %}
<option value="{{team.team_name}}">{{team.team_name}}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
</br>
<input type="submit" id="getTeamInfo" value="Check" />
<input type="button" class="back2to1" value="Back" />
</form>
<h2><u> Results </u></h2>
<h3> Members: </h3>
<table rules="cols">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody id="member-table">
</tbody>
</table>
</div>
</div>
<div style="display:none;" id="stage3">
Expand Down
13 changes: 13 additions & 0 deletions huntserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from subprocess import check_output
from django.http import HttpResponse, HttpResponseNotFound
from django.contrib.auth import authenticate
import json

from .models import *
from .forms import *
Expand Down Expand Up @@ -66,6 +67,18 @@ def registration(request):
else:
return HttpResponse('fail-password')

# Check for correct password when doing existing registration
if(request.POST.get("data")):
team = curr_hunt.team_set.get(team_name=request.POST.get("team_name"))
# Check that the password is correct
user = authenticate(username=team.login_info.username, password=request.POST.get("password"))
if user is not None:
a = Person.objects.filter(team=team).all().values('first_name', 'last_name', 'email')
print(a)
return HttpResponse(json.dumps(list(a)))
else:
return HttpResponse('fail-password')

# Check if team already exists when doing new registration
elif(request.POST.get("check")):
if(curr_hunt.team_set.filter(team_name__iexact=request.POST.get("team_name")).exists()):
Expand Down

0 comments on commit 86dd39f

Please sign in to comment.