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:
                print('found it')
                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, 'register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo 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(commit=True)
            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()

    context_dict = {"user_form": user_form, "profile_form": profile_form}

    return render(request, "first_app/registration.html", context_dict)
Exemplo n.º 3
0
def signup_page(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)  #hasing password
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  #sets up ne to one relationship

            # can also be used to upload a CSV
            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, 'first_app/signup.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
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():
            # SAVE USER
            user = user_form.save()
            # HASH PASSWORD
            user.set_password(user.password)
            # SAVE CHANGES FOR HASHED PASSWORD
            user.save(0)

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

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

            profile.save()

            registered = True

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

    return render(request, 'first_app/registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Exemplo n.º 5
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()

            #to prevent from collision commit=false
            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, 'first_app/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 6
0
def signup(request):
    registered = False

    #defining a post method to a form and saving it to db
    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, 'first_app/signup.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 7
0
def register(request):

    registered = False

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

        # Get info from "both" forms
        # It appears as one form to the user on the .html page

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Check if they provided a profile picture

            # Registration Successful!
            registered = True

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

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

# This is the render and context dictionary to feed
# back to the registration.html file page.
    return render(
        request, 'login.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 8
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()

            # Hash the password
            user.set_password(user.password)

            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful!
            registered = True

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'first_app/_register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 9
0
def Registration(request):
    topics = Topic.objects.all()
    registered = False
    if request.method == "POST":
        print("Registration Request type is - Get")
        """
            Invoke both the forms 1.user_form  2.UserProfileInfoForm in the views
            from forms.py 
            1. UserForm is linked with django's default model User
            2. UserProfileInfoForm is linked with model UserProfileInfo which describes the two additional fields
        """
        user_form = UserForm(request.POST)
        profile_form = UserProfileInfoForm(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
            """
                The above line is actually relates to object reference 'user' defined in model.py by user = models.OneToOneField(User, on_delete='Cascade')
            """
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
            #return HttpResponseRedirect(reverse(Registration))
        else:
            print("Form is invalid. Errors - " + user_form.errors +
                  profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
        print("Registration Request type is - Get")
    return render(
        request, 'first_app/Registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'all_topics': topics,
        })
Exemplo n.º 10
0
def register(request):

    registered = False

    if request.method == 'POST':
        print('form filled')
        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)  #password hashing
            user.save()  #save user data

            profile = profile_form.save(commit=False)
            profile.user = user  #one to one relation

            if 'profile_pic' in request.FILES:  #iterating over media files uploaded in the registration process
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True
            print('form saved')
        else:
            print(user_form.errors,
                  profile_form.errors)  #error printing on the forms

    else:
        print('form created')
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, "first_app/registration.html", {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 11
0
def register(request):

    registered = False

    if request.method == 'POST':
        # Grab the data from the POST
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check if the form is valid and save the user data
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            # Hash the user password
            user.set_password(user.password)
            # Save the latest data
            user.save()

            # commit the profile information without saving them: This is because we havent
            # checked if the user provided an image(profile pics)
            profile = profile_form.save(commit=False)
            # Set the user id. this is used to fulfile the OneToOneField
            # Registered on our Form.py file
            profile.user = user

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

                profile.save()

                registered = True

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

    return render(request, 'first_app/registration.html',
                      {"profile_form": profile_form, 'user_form': user_form, 'registered': registered})
Exemplo n.º 12
0
def authoreg(request):
    print("authoreg called")
    registered = False
    if request == "POST":
        print("Inside 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()
            print("Saved data of user")
            profile = profile_form.save(commit=False)
            profile.user = user

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

            profile.save()
            print("Saved data of profile")

            registered = True
            print("Updated registered tag!!")

        else:
            print(user_form.errors, profile_form.errors)
    else:
        print("Get portion executed!!")
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'first_app/authoreg.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 13
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():
            # Save form to a database
            user = user_form.save()
            # Hash the password
            user.set_password(user.password)
            # Save the password to the user information
            user.save()

            profile = profile_form.save(commit=False)
            # OneToOne Relationship
            profile.user = user

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

            profile.save()

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

    return render(
        request, 'first_app/registration.html', {
            'registered': registered,
            'user_form': user_form,
            'profile_form': profile_form
        })
Exemplo n.º 14
0
def Register(request):

    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('index'))

    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, 'first_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })