Ejemplo n.º 1
0
Archivo: views.py Proyecto: ckizer/tod
def quickstart(request):
    """gives the user a choice between login in and creating an anonymous game
    """
    if request.method == "POST":
        anonymous_users = User.objects.filter(username__startswith="anonymous").order_by("-username")
        if anonymous_users.count():
            last_number = anonymous_users[0].username.split("_")[-1]
            if last_number.isdigit():
                username = "******" % (int(last_number) + 1)
            else:
                username = "******"
        else:
            username = "******"
        values = {
            "username": username,
            "password": "******"
            }
        form = UserForm(values, password=values.get("password"))
        if form.is_valid():
            user = form.save()
            user = authenticate(username=values["username"], password=values['password'])
            login(request, user)
        return HttpResponseRedirect("/game/create/")
        
    template = "game/quickstart.html"
    return locals()
Ejemplo n.º 2
0
Archivo: views.py Proyecto: ckizer/tod
def register(request):
    template = "registration/register.html"
    if request.method == "POST":
        values = request.POST.copy()
        
        registration_form = UserForm(values, password=values.get("password"))
        if registration_form.is_valid():
            user = registration_form.save()
            user = authenticate(username=values["username"], password=values['password'])
            login(request, user)
            return HttpResponseRedirect("/")
    else:
        registration_form = UserForm()
    return locals()
Ejemplo n.º 3
0
Archivo: views.py Proyecto: ckizer/tod
def save_anonymous_game(request, game_id):
    """Saves the game with a new username and password
    """
    game = get_object_or_404(Game, pk=game_id)
    if request.method == "POST":
        values = request.POST.copy()

        save_user_form = UserForm(values, instance=request.user, password=values.get("password"))
        if save_user_form.is_valid():
            user = save_user_form.save()
            user = authenticate(username=values["username"], password=values['password'])
            login(request, user)
            return HttpResponseRedirect("/game/")
        else:
            players = game.players.all()
            winners = game.getWinners()
    is_anonymous = True if request.user.username.startswith("anonymous_") else False
    template = "game/over.html"
    return locals()