Example #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.PlayerProfile` object.
    """
    if request.method == 'POST':
        user_form = UserCreationForm(request.POST, prefix='user')
        player_form = PlayerProfileForm(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 = PlayerProfileForm(prefix='player')

    context = {
        'user_form': user_form,
        'player_form': player_form,
    }
    return direct_to_template(request, template, context)
Example #2
0
    def account_setup(self, request, template='tms/registration.html'):
        if request.method == 'POST':
            player_form = PlayerProfileForm(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 = PlayerProfileForm()

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