Пример #1
0
def filled_registration(request):
    """Registration already filled for participants on previous years."""
    if request.method == 'POST':
        emailForm1 = EmailOldUserForm(request.POST, prefix="email1")
        usr1 = PlayerForm(prefix="usr1")
        reg1 = RegistrationForm(prefix="reg1")
        usr2 = PlayerForm(prefix="usr2")
        reg2 = RegistrationForm(prefix="reg2")
        trn = OpenTournamentChoiceForm()

        if emailForm1.is_valid():
            try:
                oldusr = User.objects.get(email=emailForm1.cleaned_data['email'])
            except ObjectDoesNotExist:
                return render(request, 'players/register.html', {
                        "usr1": usr1,
                        "reg1": reg1,
                        "usr2": usr2,
                        "reg2": reg2,
                        "trn": trn,
                        "email1": emailForm1,
                        })
            send_mail('Enregistrement tournoi Asmae', 'Confirmez votre inscription au tournoi ici : http://'+request.META['HTTP_HOST']+ \
                '/players/fregister?email=%s&token=%s' % (oldusr.email, str(hash(oldusr))), '*****@*****.**', [emailForm1.cleaned_data['email']], fail_silently=False)
        else:
            return render(request, 'players/register.html', {
                "usr1": usr1,
                "reg1": reg1,
                "usr2": usr2,
                "reg2": reg2,
                "trn": trn,
                "email1": emailForm1,
                })
    else:
        email = request.GET.get('email', None)
        token = request.GET.get('token', None)
        usr1 = PlayerForm(prefix="usr1")
        if email != None and token != None:
            try:
                oldusr = User.objects.get(email=email)
                if hash(oldusr) == int(token):
                    usr1 = PlayerForm(player_email=email, prefix="usr1")
            except ObjectDoesNotExist:
                pass
        reg1 = RegistrationForm(prefix="reg1")
        usr2 = PlayerForm(prefix="usr2")
        reg2 = RegistrationForm(prefix="reg2")
        trn = OpenTournamentChoiceForm()
        emailForm1 = EmailOldUserForm(prefix="email1")
        return render(request, 'players/register.html', {
            "usr1": usr1,
            "reg1": reg1,
            "usr2": usr2,
            "reg2": reg2,
            "trn": trn,
            "email1": emailForm1,
            })

    return redirect('players.views.register')
Пример #2
0
def unregister(request):
    """ Request to delete all the data of a player on the database """
    form = EmailOldUserForm()

    if request.method == 'POST':
        form = EmailOldUserForm(request.POST)
        if form.is_valid():
            try:
                user = User.objects.get(email=form.cleaned_data['email'])
                send_mail('Suppression de votre adresse sur le site SEP2015E', "Vous avez demandé que votre adresse soit supprimée de notre base de données. Si vous êtes certain de votre choix, cliquez sur le lien suivant ou copiez-collez le dans votre navigateur.\n\nhttp://"+request.META['HTTP_HOST']+"/players/unregister_confirm?user="******"&token="+str(hash(user))+"\n\nSi vous n'avez pas demandé à ce que votre adresse soit supprimée, veuillez ignorer ce message.", '*****@*****.**', [user.email], fail_silently=False)
                return HttpResponseRedirect("/")
            except ObjectDoesNotExist:
                form.add_error('email', "Cette adresse n'est pas présente dans notre base de données.")

    return render(request, 'players/unregister.html', {\
            'form_email': form, \
            })