Ejemplo n.º 1
0
def userprofile(request):
    profileform = UserProfileInfoForm

    if request.method == "POST":
        profileform = UserProfileInfoForm(request.POST)

        if profileform.is_valid():
            profileform.save()
            return index(request)

    return render(request,
                  'AppTwo/profileform.html',
                  context={"profileform": profileform})
Ejemplo n.º 2
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'sec_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 3
0
def register(request):

    registered = False
    if request.method == "POST" and registered == False:

        user_form = UserProfileForm(request.POST)
        userprof_form = UserProfileInfoForm(request.POST, request.FILES)

        if user_form.is_valid() and userprof_form.is_valid():

            user = user_form.save(commit=True)
            user.set_password(user.password)
            user.save()

            userprof = userprof_form.save(commit=False)
            userprof.user = user

            if 'profile_pic' in request.FILES:
                print('found it')
                userprof.profile_pic = request.FILES['profile_pic']
            else:
                print('No pic found')

            userprof.save()

            registered = True
            print("Completed")
        else:

            print(user_form.errors, userprof_form.errors)

    else:
        user_form = UserProfileForm()
        userprof_form = UserProfileInfoForm()

    return render(
        request, "register.html", {
            'user_form': user_form,
            'userprof_form': userprof_form,
            'registered': registered
        })
Ejemplo n.º 4
0
def register_form(request):

    registered = False

    if request.method == 'POST':

        user_form = UserForm(data=request.POST)
        user_profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and user_profile_form.is_valid():

            user = user_form.save()
            #    below hashes the submitted password
            user.set_password(user.password)
            user.save()

            profile = user_profile_form.save(commit=False)
            # below tell django that the userProfileInfoForm is part of the UserForm - create the 1TO1 relationship
            profile.user = user

            # This check if profile_pic is included in the request files, if so set profile_pic to = the profile_pic
            #                                                                                     from the request files
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

        else:
            print(user_form.errors, user_profile_form.errors)
    else:
        user_form = UserForm()
        user_profile_form = UserProfileInfoForm()

    return render(
        request, 'AppTwo/register.html', {
            'user_form': user_form,
            'user_profile_form': user_profile_form,
            'registered': registered
        })
Ejemplo n.º 5
0
def register(request):
    registered = False
    #return HttpResponse("<em>Hello World!</em>")

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request,
                  'AppTwo/registration.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })