Exemple #1
0
def register(request):
    invite = request.session['profile-invite']
    if request.method == 'POST':
        userForm = forms.UserForm(request.POST, prefix='user')
        profileForm = ProfileForm(request.POST, prefix='profile')
    else:
        userForm = forms.UserForm(prefix='user')
        profileForm = ProfileForm(prefix='profile')
    if userForm.is_valid() and profileForm.is_valid():
        oldUser = None
        try:
            oldUser = User.objects.get(username__exact=userForm.cleaned_data['username'])
        except ObjectDoesNotExist, e:
            pass
        if not oldUser:
            user = User.objects.create_user(userForm.cleaned_data['username'], userForm.cleaned_data['email'], userForm.cleaned_data['password'])
            user.save()
            invite.claimer = user
            invite.save()
            profile = user.minecraftprofile
            profile.mc_username = profileForm.cleaned_data['mc_username']
            profile.save()
            user = authenticate(username=userForm.cleaned_data['username'], password=userForm.cleaned_data['password'])
            notification.send_now([invite.creator], "invite_accepted", {"new_user": user})
            login(request, user)
            del request.session['profile-invite']
            return HttpResponseRedirect("/")
Exemple #2
0
def edit(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST, instance=request.user.minecraftprofile)
    else:
        form = ProfileForm(instance=request.user.minecraftprofile)
    if form.is_valid():
        profile = request.user.minecraftprofile
        profile.mc_username = form.cleaned_data['mc_username']
        profile.save()
        return HttpResponseRedirect(reverse('local.views.profile'))
    return render_to_response('local/edit.html', {"form":form}, context_instance = RequestContext(request))