Beispiel #1
0
def registration(request, template="tms/registration.html"):
    """
    Displays registration form. After submitting :model:`auth.User` account is
    created along with a new :model:`tms.Player` object.
    """
    if request.method == "POST":
        user_form = UserCreationForm(request.POST, prefix="user")
        player_form = PlayerForm(request.POST, prefix="player")

        if user_form.is_valid() and player_form.is_valid():
            user = user_form.save(commit=False)
            user = _configure_user(user)

            credentials = {"username": user.username, "password": user_form.cleaned_data["password1"]}
            auth.login(request, auth.authenticate(**credentials))

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

            msg = _("Registration successfull. " "You are now logged in as %s") % user.username
            messages.success(request, msg)
            return HttpResponseRedirect(reverse("tms:index"))

    else:
        user_form = UserCreationForm(prefix="user")
        player_form = PlayerForm(prefix="player")

    context = {"user_form": user_form, "player_form": player_form}
    return direct_to_template(request, template, context)
Beispiel #2
0
def registration(request, template='tms/registration.html'):
    """
    Displays registration form. After submitting :model:`auth.User` account is
    created along with a new :model:`tms.Player` object.
    """
    if request.method == 'POST':
        user_form = UserCreationForm(request.POST, prefix='user')
        player_form = PlayerForm(request.POST, prefix='player')

        if user_form.is_valid() and player_form.is_valid():
            user = user_form.save(commit=False)
            user = _configure_user(user)

            credentials = {'username': user.username,
                           'password': user_form.cleaned_data['password1']}
            auth.login(request, auth.authenticate(**credentials))

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

            msg = _('Registration successfull. '
                    'You are now logged in as %s') % user.username
            messages.success(request, msg)
            return HttpResponseRedirect(reverse('tms:index'))

    else:
        user_form = UserCreationForm(prefix='user')
        player_form = PlayerForm(prefix='player')

    context = {
        'user_form': user_form,
        'player_form': player_form,
    }
    return direct_to_template(request, template, context)
Beispiel #3
0
    def account_setup(self, request, template="tms/registration.html"):
        if request.method == "POST":
            player_form = PlayerForm(request.POST)

            if player_form.is_valid():
                user = request.session[TmsNyxAuth.USER_SESSION_KEY]
                user = _configure_user(user)
                user.save()

                player = player_form.save(commit=False)
                player.user = user
                player.from_nyx = True
                player.save()

                messages.success(request, _("Registration successfull."))
                return super(TmsNyxAuth, self).post_auth(request, user)
        else:
            player_form = PlayerForm()

        context = {"player_form": player_form}
        return direct_to_template(request, template, context)