Example #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
                            })
Example #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})
def register(request):
    # Assume user is not registered
    registered = False

    # Check if form submit method is post
    if request.method == "POST":
        # get form data
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileFormInfo(data=request.POST)

        # check if forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # grab details from base user form and save to db
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            # grab details from profile form
            profile = profile_form.save(commit=False)
            profile.user = user

            # check if these is a picture in media files
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            # save it to db if it exists
            profile.save()

            # set registered to true so that it passes the form to template
            registered = True
        else:
            # print errors if there are problems
            print(user_form.errors, profile_form.errors)

    else:
        # if form not posted, create form variables
        user_form = UserForm()
        profile_form = UserProfileFormInfo()
    # render register template to allow user to register
    return render(request, 'basic_app/register.html',
                            {'user_form':user_form,
                            'profile_form':profile_form,
                            'registered':registered})
Example #4
0
def register(request):
    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = User_Profile_Info(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()
            register = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = User_Profile_Info
    return render(
        request, 'basic_app/regist.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #5
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)
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
        })
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})
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 skills_page(request):
    skill=None
    submitted = False
    if request.method=="POST":
        user_form=UserForm(data=request.POST)
        skills_form=SkillsForm(data=request.POST)

        if user_form.is_valid() and skills_form.is_valid():
            user = User.objects.get(pk=username)




            user.userprofileinfo.Area_of_Interests = "NNGO"
            user.save()

        else:
            print("Error")
    else:
        return render(request,'basic_app/index.html')

    return render(request,'basic_app/index.html',{'skills_form':skills_form,'user_form':user_form,'skill':skill,'submitted':submitted})
Example #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)                #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
        })
Example #11
0
def register(request):
    logout(request)
    registered = False

    if request.method == "POST":

        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            print("NAME: " + user_form.cleaned_data['username'])
            user = user_form.save()
            user.set_password(user.password)
            user.save()

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

    return render(request, 'basic_app/registration.html', {
        'user_form': user_form,
        'registered': registered
    })
Example #12
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('ERROR')
            print(user_form.errors, profile_form.errors)

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

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'registered': registered
    }
    return render(request, 'basic_app/registration.html', context)
Example #13
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            #user_form ko sedha save kar
            user = user_form.save()
            pas = user.password
            user.set_password(user.password)
            user.save()
            #we grabed  ser information password set kiye fir save kiye database me
            profile = profile_form.save(commit=False)
            profile.user = user
            #one to one in models
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()

            registered = True
        else:
            #invalid
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserInfoForm()
    if registered == False:
        return render(request, 'register.html', {
            'user_form': user_form,
            'profile_form': profile_form
        })
    else:
        check = authenticate(username=user.username, password=pas)
        if check:
            if check.is_active:
                login(request, check)
                # save in audit table
                a = audit(name=user.username,
                          login_time=str(datetime.now()),
                          logout_time='')
                a.save()
                dict = audit.objects.all()
                # //u can send dict to any html page to display db contents
                return render(request, 'other.html', {
                    'username': user.username,
                    'password': pas
                })
            else:
                return HttpResponse('account not active')
        else:
            return HttpResponse(
                'invalid login supplied username {} password {}!'.format(
                    user.username, pas))
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,
        })
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
        })
Example #16
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})
Example #17
0
def user_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(
        ) 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()
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()
            messages.add_message(request, messages.SUCCESS,
                                 'You have successfully registered yourself')
            registered = True
            return HttpResponseRedirect(reverse('user_login'),
                                        {'messages': messages})

        elif user_form.cleaned_data['password'] != user_form.cleaned_data[
                'confirm_password']:
            user_form.add_error('confirm_password',
                                'The passwords do not match')
        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,
            'messages': messages
        })
Example #18
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
                  })
Example #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 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
        })
Example #20
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)
Example #21
0
def register(request):

    # variable to indicate if someone is registered or not
    registered = False

    if request.method == "POST":
        user_form = UserForm(
            data=request.POST)  # contains the data from UserForm
        profile_form = UserProfileForm(
            data=request.POST)  # contains the data from UserProfileForm

        # check if both the forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # save the user information to the database
            user = user_form.save()
            # hashing the password entered in by the user
            user.set_password(user.password)
            # save the hashed password to the database
            user.save()

            # save the extended user information to the database
            profile = profile_form.save(commit=False)

            # setup the one to one relationship with User
            profile.user = user

            # check if a profile picture was uploaded
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

        else:  # both forms not valid
            print(user_form.errors, profile_form.errors)

    else:
        # not a post method - user did not fill in form yet, set everything up
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, "basic_app/registration.html", {
            "registered": registered,
            "user_form": user_form,
            "profile_form": profile_form
        })
Example #22
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})
Example #23
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()        
            user.set_password(user.password)       
            user.save()
            registered = True
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    return render(request,'basic_app/registration.html',{'user_form':user_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
        })
Example #25
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
        })
Example #26
0
def register(request):

    registered = False

    if request.method == 'POST':

        userform = UserForm(data=request.POST)
        userprofile = UserProfileForm(data=request.POST)
        print("heLooo daaa ithu", userform.is_valid(), "ithum noku",
              userprofile.is_valid())
        if userform.is_valid() and userprofile.is_valid():

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

            profile = userprofile.save(commit=False)
            print("here")
            profile.user = user

            if 'profile_pic' in request.FILES:

                print("Found")
                profile.profile_pic = request.FILES['profile_pic']
            else:
                print("Not found")

            profile.save()
            registered = True
        else:
            print("errorrs daaa")
            print(userform.errors, userprofile.errors)

    else:
        userform = UserForm()
        userprofile = UserProfileForm()

    return render(request, 'basic_app/registration.html', {
        'form1': userform,
        'form2': userprofile,
        'registered': registered
    })
Example #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
        })
Example #28
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=False)
            username=user_form.cleaned_data['username']
            password=user_form.cleaned_data['password']

            try:
                validate_password(password,user)
            except ValidationError as e:
                user_form.add_error('password',e)
                return render(request,'basic_app/registration.html',{'user_form':user_form,'profile_form':profile_form,'registered':registered})
            user.set_password(user.password)
            user.save()

            profile=profile_form.save(commit=False)
            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,'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
        })
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
        })
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})
def register(request):

    # variable to check if register process successfull, also used in register.html
    registered = False

    if request.method == 'POST':
        # grab the data from form
        user_form = UserForm(data=request.POST)
        user_profile_form = UserProfileInfoForm(data=request.POST)

        # check if data is valid
        if user_form.is_valid() and user_profile_form.is_valid():
            # save the user_form data, keep it on variabel to do hashing
            user = user_form.save()
            # perform hashing
            user.set_password(user.password)
            user.save()

            # save the user profile data, commit set as false to make sure it's not created twice
            # as this is linked model
            profile = user_profile_form.save(commit=False)
            # linked with user class
            profile.user = user

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

            # save the profile
            profile.save()

            registered = True
        else:
            # simply print the error from both user & user profile class
            print(user_form.errors, user_profile_form.errors)
    else:
        user_form = UserForm()
        user_profile_form = UserProfileInfoForm()

    return render(
        request, 'basic_app/register.html', {
            'user_form': user_form,
            'user_profile_form': user_profile_form,
            'registered': registered
        })
Example #33
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
        })