def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password1']
            )
            if 'invitation' in request.session:
                #Retrieve the invitation object
                invitation = Invitation.objects.get(id=request.session['invitation'])
                #Create friendship from user to sender
                friendship = Friendship(from_friend=user, to_friend=invitation.sender)
                friendship.save()
                #Create friendship from sender to user
                friendship = Friendship(from_friend=invitation.sender, to_friend=user)
                friendship.save()
                #Delete the invitation from the database
                invitation.delete()
                del request.session['invitation']
            return HttpResponseRedirect('/register/success/') 
    else:
        form = RegistrationForm()
        print(form.as_p())
    variables = RequestContext(request, {'form' : form})
    return render_to_response('registration/register.html', variables)
Пример #2
0
def register_page(request):
    """用户注册"""

    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username = form.cleaned_data['username'],
                password = form.cleaned_data['password1'],
                email = form.cleaned_data['email']
                )
            ## 来自于邀请的注册
            if 'invitation' in request.session:
                invitation = Invitation.objects.get(id=request.session['invistation'])
                #建立好友关系
                friendship = Friendship(from_friend=user, to_friend=invitation.sender)
                friendship.save()

                ## 双向
                friendship = Friendship(from_friend=invitation.sender, to_friend=user)
                friendship.save()

                invitation.delete()
                del request.session['invitation']

            return HttpResponseRedirect('/register/success/')

    else:
        form = RegistrationForm()

    return render_to_response('registration/register.html',
                              {'form': form}
                              )
Пример #3
0
def register_page(request):
    if request.method=='POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            User.create_user(username=form.cleaned_data['username'],password=form.cleaned_data['password1'],email=form.cleaned_data['email'])
            return HttpResponseRedirect("/register/success")
    else:
        form = RegistrationForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response('registration/register.html',variables)
Пример #4
0
def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email']
            )
            return redirect('/register/success/')
    else:
        form = RegistrationForm()
    return render(request, 'registration/register.html', {'form':form } )