コード例 #1
0
def register(request):
    #TODO(mike): Redirect failed registration into correct window instead of new one
    registered = False
    if request.method == 'POST':
        user_form = UserRegistrationForm(
            data=request.POST)  #Fills form with POST data
        profile_form = UserProfile(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.save()  #saves new user
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()  # saves new user profile
            registered = True
        else:
            print user_form.errors, profile_form.errors  #Will output to apache's error.log

    else:
        user_form = UserRegistrationForm(
        )  #creates forms to pass to the front end for filling out
        profile_form = UserProfile()

    return render(
        request, 'register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #2
0
def settings(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            profile_form = UserProfile(data=request.POST,
                                       instance=request.user)
            if profile_form.is_valid():
                profile_form.save()
            return HttpResponseRedirect('/')
        else:
            profile_form = UserProfile()
            return render(request, 'settings.html',
                          {'profile_form': profile_form})
    return HttpResponse(status=401)  # Not Authenticated