Ejemplo n.º 1
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,'basic_app/registration.html',
                            {'user_form':user_form,
                            'profile_form': profile_form,
                            'registered': registered
                            })
Ejemplo n.º 2
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(data=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()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(request,'basic_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":
        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)
            # the reason for not commit is we dont want to overwrite it
            # the following code is build the one to one relationship
            profile.user = user
            # same type of method dealing with other files
            #  live .csv .pdf resume something like that
            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, 'basic_app/registration.html',
                    {'user_form':user_form,
                    'profile_form':profile_form,
                    'registered':registered})
Ejemplo n.º 4
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(data=request.POST)

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

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

            # Hash the password (goes to settings.py file and sets it as hash)
            user.set_password(user.password)

            # Update (saving changes to) the database with the Hashed password
            user.save()

            # EXTRA information

            # Can't commit (save to database) 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:
                # 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)
            # the above just prints out the actual errors
    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    return render(request, 'basic_app/registration.html', context)
Ejemplo 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() and user_form.cleaned_data['password'] == user_form.cleaned_data['confirm_password']:
            user=user_form.save()
            user.set_password(user.password)
            user.save()

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

            profile.save()
            registered=True

        else:
            print(user_form.errors,profile_form.errors)

    else:
        user_form=UserForm()
        profile_form=UserProfileInfoForm()
    return render(request,'basic_app/SignUp_FormValidation.html',{'user_form':user_form,
                                                        'profile_form':profile_form,
                                                        'registered':registered})
Ejemplo n.º 6
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:
                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()
            registered = True
        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()


    return render(request,"basic_app/registration.html",context={'user_form':user_form,
    'profile_form' : profile_form,
    'registered': registered})
Ejemplo n.º 7
0
def register(request):

    registered = False

    if request.method == "POST":
        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

            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, "basic_app/registeration.html", {
            "user_form": user_form,
            "userprofile_form": profile_form,
            "registered": registered
        })
Ejemplo n.º 8
0
def register(request: "HttpRequest") -> HttpResponse:

    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 = user_form.save()
            user.set_password(user.password)
            user.save()

            profile: UserProfileInfo = profile_form.save(
                commit=False
            )  # To avoid saving to the database directly and perform operations before.
            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, "basic_app/registration.html", {
            "user_form": user_form,
            "profile_form": profile_form,
            "registered": registered
        })
Ejemplo n.º 9
0
def register(request):
    registered = False
    user_form = UserForm()
    profile_form = UserProfileInfoForm()
    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():
            # for user
            user = user_form.save()
            user.set_password(user.password)  # set hashing password
            user.save()

            profile = profile_form.save(
                commit=False)  # 表單.save() 會回傳 該表單連結的 Data Model
            profile.user = user

            if 'profile_pics' in request.FILES:  # for image files
                profile.profile_pics = request.FILES[
                    'profile_pics']  # profile_pics 是剛剛前面在 建立 models 針對 pic的設定

            profile.save()
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    context = {
        "registered": registered,
        "user_form": user_form,
        "profile_form": profile_form
    }

    return render(request, 'basic_app/registration.html', context=context)
Ejemplo n.º 10
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,'basic_app/registration.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered})
Ejemplo n.º 11
0
def register(request):
    registered=False
    if request.method=="POST":
        profile_form=UserProfileInfoForm(data=request.POST)
        user_form=UserForm(data=request.POST)
        if profile_form.is_valid() and user_form.is_valid():

            user=user_form.save()
            user.set_password(user.password)#this line hashes the password into unique code
            user.save()

            profile=profile_form.save(commit=False) #That's useful when you get most of your model data from a form, but need to populate some null=False fields with non-form data. Saving with commit=False gets you a model object, then you can add your extra data and save it.
            profile.user=user#this line of code means that, the profile will not override the data in user form but will form a OneToOneField relation with user.

            if 'profile_pic' in request.FILES:
                profile.profile_pic=request.FILES['profile_pic']#sutax code for saving profile_pic

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

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


    return render(request,'basic_app/registration.html',
                    {'user_form':user_form,
                    'profile_form':profile_form,
                    'registered':registered})
Ejemplo n.º 12
0
def register(request):
    #aassume first user not registered
    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 directed to database
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            #make sure set up one to one relationship
            #to prevent overide the user
            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()
        #registered = True
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo 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():

            user = user_form.save()
            # This is about "PASSWORD_HASHERS" item defined within settings.py
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  # OneToOne relationship user = models.OneToOneField(User) models.py

            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, 'basic_app/registration.html',
                            {'user_form': user_form,
                             'profile_form': profile_form,
                             'registered': registered,})
Ejemplo n.º 14
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(data=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()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 15
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 = _save_user(user_form)
            _save_user_profile(profile_form, request, user)
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    form_dict = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered,
    }
    return render(request, 'basic_app/registration.html', form_dict)
def register(request):

    registered = False

    #Check if user clicked Register button
    if request.method == "POST":
        #we will use following values in registration.html file as template tags
        #Not sure  ,I think here we get data from user and save it to variable
        #it happens after user click Register button
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        #If all data we get from user is valid then do following
        if user_form.is_valid() and profile_form.is_valid():

            #After check data is valid we save it

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

            profile = profile_form.save(commit=False)
            #Not sure I think somehow we connect form results
            #Not sure but I think this line has some relation with line(I write it down) in models.py under UserProfileInfoForm class
            #user  = models.OneToOneField(User)
            profile.user = user

            #Here we check if picture submited
            if 'profile_pic' in request.FILES:
                #here we assign picture to profile.profile_pic
                #This profile_pic are from models.py ,you can see it there
                #Not Sure:like profile_pic is in models.py  then it connected to forms.py with UserProfileInfoForm
                #then connected to views.py via UserProfileInfoForm
                profile.profile_pic = request.FILES['profile_pic']
            #Here we save profile ,no matter there is pic or not,it is outside of if
            profile.save()

            #We will use this boolen on registration.html file
            #so if user registered we will show 'Thank you for your registration'
            registered = True
        else:
            #here we print validation errors if happens
            print(user_form.errors, profile_form.errors)
    else:
        #This is for fresh page,I mean above code are mostly about what will happen if user clicks 'Register' button
        #But here we just display forms(like inputboxes,browse file and so),This form is organized by forms.py particularly by UserForm and UserProfileInfoForm
        #Basicly first page shows form with below code then user fills info then click button after click above code works
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    #This returns page,'basic_app/registration.html' is location of html
    #{'user_form':user_form,'profile_form':profile_form,'registered':registered} these things are basicly context ,template tags on html will use these values
    #example this {{ user_form.as_p }}  tag in registration.html
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 17
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)                #hashing password
    #         user.save()
    #
    #         profile = profile_form.save(commit=False)
    #         profile.user = user                             #Defing one to one relation with 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()
    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, 'basic_app/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 18
0
def register(request):

    registered = False

    # get info from "both" forms
    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 form to database
            user = user_form.save()

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

            # update with hashed password
            user.save()

            # now with the extra info.

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

            # set One to One relationship between UserForm and UserPofileInfoForm
            profile.user = user

            # checking for any profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # if yes, then grab it from the POST from reply
                profile.profile_pic = request.FILES['profile_pic']

            # now save model
            profile.save()

            # registration successful
            registered = True

        else:
            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, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
        })
Ejemplo n.º 19
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms

        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=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 using argonpassword hasers algorithm
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)

            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')

                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()

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

    # remenber why use the register False
    # this is used instant of the instance stuff
    registered = False

    # checking if is a Post reqeust
    if request.method == 'POST':

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

        # check if it is valid
        if user_form.is_valid() and profile_form.is_valid():

            #save the user_form first with an instance
            user = user_form.save()

            # set a password sha
            user.set_password(user.password)

            # and save all
            user.save()

            # sending it to the database but not saving yet
            profile = profile_form.save(commit=False)

            #setting all the relationship
            profile.user = user

            # check for profile pic
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

                # save everything
                profile.save()

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

    return render(request=request,
                  template_name='basic_app/registration.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Ejemplo n.º 21
0
def register(request):
    registered = False

    if request.method == "POST":
        # Get info from both forms
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check if 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 with the algorithms
            user.set_password(user.password)

            # Now save the password
            user.save()

            # Don't save yet profile form, wait until modified
            profile = profile_form.save(commit=False)

            # Create the One to One Relationship from the models
            profile.user = user

            # Check if profile picture is provided
            if "profile_pic" in request.FILES:
                print("Found it")
                profile.profile_pic = request.FILES["profile_pic"]

            # Save profile form to Database
            profile.save()

            # Registration successful
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        #  It was not a HTTP Post request, so forms are render blank
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, "basic_app/registration.html", {
            "user_form": user_form,
            "profile_form": profile_form,
            "registered": registered
        })
Ejemplo n.º 22
0
def register(request):
    
    ##default to false to check
    ##
    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()
            
            ##hashes password
            ##
            user.set_password(user.password)
            user.save()
    
            ##commit false to avoid collisions
            ##
            profile = profile_form.save(commit=False)
            
            ##creates one to one relationship
            ##
            profile.user = user 
            
            ##check if picture submitted
            ##
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            
            profile.save()
            
            registered = True
        
        ##invalid form
        ##
        else:
            print(user_form.errors, profile_form.errors)
          
    ##if not set to post
    ##
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
        
    return render(request, 'basic_app/registration.html', 
                  {'user_form':user_form,
                   'profile_form':profile_form,
                   'registered':registered})
Ejemplo n.º 23
0
def register(request: HttpRequest) -> HttpResponse:
    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()

            # Hash the password using 'set_password' method
            user.set_password(user.password)

            # Save the model to DB
            user.save()

            # Save profile form without committing
            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:
            context = {
                'error_message':
                'There seems to be an error in the form you filled. Please retry'
            }
            print(user_form.errors)
            print(profile_form.errors)
            return render(request=request,
                          template_name='basic_app/registration.html',
                          context=context)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    context = {
        'registered': registered,
        'user_form': user_form,
        'profile_form': profile_form,
    }
    return render(request=request,
                  template_name='basic_app/registration.html',
                  context=context)
Ejemplo n.º 24
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()

            #hash the password and save it!
            user.set_password(user.password)
            user.save()

            profile=profile_form.save(commit=False)

            #one to one relationship
            profile.user = user

            #profile picture
            if 'profile_pic' in request.FILES:
                print('found it!')

                #link the profile_pic with the request.FILES
                profile.profile_pic = request.FILES['profile_pic']

            #now we want to save the profile
            profile.save()
            #registration Successful
            registered = True

        #if one of them is invalid
        else:
            print(user_form.errors,profile_form.errors)



    else:
    #if method isnt POST we just render forms as blank! easy!
        user_form=UserForm()
        profile_form=UserProfileInfoForm()

    return render(request,'basic_app/register.html',
                           {'user_form':user_form,
                            'profile_form':profile_form,
                            'registered':registered})
def register(request):

    registered = False

    if request.method == 'POST':
        #form submitted
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        #check form validity
        if user_form.is_valid() and profile_form.is_valid():
            #form is valid

            #save the user_form
            user = user_form.save()
            #hash the password
            user.set_password(user.password)
            #save
            user.save()

            #save the profile_form - but do not commit the changes as yet as the file & other data is not present
            profile = profile_form.save(commit=False)
            #set the profile's user
            profile.user = user

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

            #finally save the profile form
            profile.save()

            registered = True
        else:
            #form is invalid
            print(user_form.errors)
            print(profile_form.errors)
    else:
        #1st time load
        #create empty forms
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

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

    registered = False

    if request.method == 'POST':

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

        # DB

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

            # Save USER TO DB
            user = user_form.save()

            # This logic is setting the password to DB AS hashed
            user.set_password(user.password)

            user.save()

            # This is checking if this info exist in the DB BY SETTING IT TO FALSE
            profile = profile_form.save(commit=False)

            profile.user = user

            # Checking if there is profile pict from this new user
            if 'profile_pic' in request.FILES:
                print('Found It!')

                profile.profile_pic = request.FILES['profile_pic']

                # Here is saving the profile pic to a DIR callled profile_pic on the project DIR and keeping ref in the DB tuple
            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 27
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)

            # Update with Hashed password
            user.save()

            # 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, 'basic_app/registration.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():

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

            profile = profile_form.save(commit=False)
            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()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 29
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():

            # Creo lo USER dalla form, e lo salvo su DB
            user = user_form.save()
            user.set_password(
                user.password
            )  # Fa l'hash della password sulla base del settings.py
            user.save()

            # Salvo le info estensione
            profile = profile_form.save(
                commit=False
            )  # Voglio essere sicuro di non avere collisioni con USER
            profile.user = user

            # Se c'è ò'immagine, la carico
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            # Registrazione completata con successo
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

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

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 30
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(data=request.POST)

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

            # Hash the password
            user.set_password(user.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()

            # Registration Successful!
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = Userform()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 31
0
def register(request):
    registered=False
    print("1")
    if request.method == "POST":
        print("2")
        user_form=UserForm(data=request.POST)
        print("3")
        profile_form=UserProfileInfoForm(data=request.POST)
        print("4")
        if user_form.is_valid() and profile_form.is_valid():
            print("5")
            user=user_form.save()
            print(user)
            print("6")
            user.set_password(user.password)
            print("7")
            user.save()
            print("8")
            profile=profile_form.save(commit=False)
            print("9")
            profile.user=user
            print("10")
            if 'profile_pic' in request.FILES:
                print("11")
                profile.profile_pic=request.FILES['profile_pic']
                print("12")
                print("mala chabuk")
            profile.save()
            print("13")
            registered=True
            print("14")

        else:
            print(user_form.errors,profile_form.errors)
            print("15")
    else:
        print("16")
        user_form=UserForm()
        profile_form=UserProfileInfoForm()
        print("17")
    print("18")
    return render(request,'basic_app/registartion.html',
                                    {'user_form':user_form,
                                        'profile_form':profile_form,
                                        'registered':registered})
Ejemplo n.º 32
0
def register(request):

    registered = False

    if request.method == 'POST':
        # GRABBING INFORMATION OF THE FORMS
        user_form = UserForm(data=request.POST)  # CONTEXT DICTIONARY
        profile_form = UserProfileInfoForm(
            data=request.POST)  # CONTEXT DICTIONARY
        # CHECK IF THE FORMS ARE VALID
        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            user.set_password(
                user.password)  # this is essentially hashing the passwords
            user.save()
            #GARBBING PROFILE PICTURE FORM AND DOUBBLE CHECKING THAT IF THERE IS THE PICTURE IN THERE !!
            profile = profile_form.save(commit=False)
            profile.user = user  #--> sets one to one relationship   #user = models.OneToOneField(User,on_delete=models.PROTECT)

            # csv or any kind of file , So you'll use very similar tactics when dealing with other types of files not just images but if you
            #want to upload a C S V a PTF the resume is set up.#You're going to be saying requests that files actually find those and you'll be dealing with the key.
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            # if every things goes right like there pic , password and valid user happens correct then we will save everything
            registered = True

        else:
            #IF THEY POST ANYTHING AND SOME OR THE OTHER THING IS NOT VALID THAN WE PRINT OUT THE ERROR!!
            print(user_form.errors, profile_form.errors)

    else:
        #IF THERE WAS NO POST  GTHEN WE JUST SET THE FORMS !!!
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

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