Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        user_form = UserForm(data=request.POST)
        player_form = PlayerForm(data=request.POST)

        if user_form.is_valid() and player_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            player = Player(user=user)
            player.save()

            user = authenticate(
                username=user_form.cleaned_data['username'],
                password=user_form.cleaned_data['password']
            )
            login(request, user)

            return HttpResponseRedirect('/')
        else:
            context = {
                'user_form': user_form
            }
            messages.error(request, 'Something went wrong...')
            return render(request, self.template_name, context)
Esempio n. 2
0
def register(request):
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        player_form = PlayerForm(data=request.POST)

        if user_form.is_valid() and player_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = player_form.save(commit=False)
            profile.user = user
            profile.save()

            registered = True

        else:
            print user_form.errors, player_form.errors
    else:
        user_form = UserForm()
        player_form = PlayerForm()

    return render_to_response(
        'register.html',
        {'user_form': user_form, 'player_form': player_form, 'registered': registered},context)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        user_form = UserForm(data=request.POST)
        player_form = PlayerForm(data=request.POST)

        if user_form.is_valid() and player_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            player = Player(user=user)
            player.save()

            user = authenticate(username=user_form.cleaned_data['username'],
                                password=user_form.cleaned_data['password'])
            login(request, user)

            return HttpResponseRedirect('/')
        else:
            context = {'user_form': user_form}
            messages.error(request, 'Something went wrong...')
            return render(request, self.template_name, context)