Ejemplo n.º 1
0
def register(request):

    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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 = UserProfileForm

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

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(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 picture was sent with the form
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

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

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Ejemplo n.º 3
0
def index(request):
    form = UserProfileForm()
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
        else:
            print("Invalid form")

    return render(request, 'index.html', {'form': form})
Ejemplo n.º 4
0
def registrations(request):

    registered = False

    if request.method == "POST":
        user_form = UserProfileForm(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  #this is the one to one relationship with the 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 = UserProfileForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'basic_app/registrations.html', {
            "registered": registered,
            "user_form": user_form,
            "profile_form": profile_form
        })
Ejemplo n.º 5
0
def register_page(request):
    user_form = Userform()
    profile_form = UserProfileForm()
    if request.method == "POST":
        user_form = Userform(request.POST)
        profile_form = UserProfileForm(request.POST, request.FILES)
        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()
            return index(request, True)
        else:
            print(user_form.errors, profile_form.errors)

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

    if request.method == 'POST':
        user_form = UserForms(request.POST)
        portfolio_form = UserProfileForm(request.POST)

        if user_form.is_valid() and portfolio_form.is_valid():
            # print('this in console')
            # print('username:'******'username'])
            # print('email:'+forms.cleaned_data['email'])
            # print('password:'******'password'])
            # print('portfolio_link:'+forms.cleaned_data['portfolio_link'])
            #
            user = user_form.save()

            user.set_password(user.password)
            # this is hashing of password

            user.save()
            # this is final saving of data in database

            portfolio = portfolio_form.save(commit=False)
            # commit is equal to false due to not letting happen collision
            # this portfolio tries to overwrite previous define user

            # so we do
            portfolio.user = user
            # this set up one to one relationship we have already defined in models
            # between user in UserProfileInfo and User (built in model)

            # FOR DIFFERENT TYPES OF FILE LIKE PDF, CSV ,IMAGES WE USE
            # REQUEST.FILES
            if 'portfolio_image' in request.FILES:
                portfolio.portfolio_image = request.FILES['portfolio_image']
                # what name has given in model we use that

                portfolio.save()
            registered = True

        else:
            print(user_form.errors, portfolio_form.errors)
    else:
        user_form = UserForms()
        portfolio_form = UserProfileForm()

    return render(
        request, 'basic_app/registration.html', {
            'user_form': user_form,
            'portfolio_form': portfolio_form,
            'registered': registered
        })
Ejemplo n.º 7
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
        })
Ejemplo n.º 8
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
    })
Ejemplo n.º 9
0
def register(request):
	registered = False

	if request.method == "POST":
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)

		if user_form.is_valid() and profile_form.is_valid():
			print("user and form valid")
			user = user_form.save()
			user.set_password(user.password)
			user.save()

			print('user saved!')
			profile = profile_form.save(commit=False)
			profile.user = user

			print("request files: %s"%request.FILES)

			if 'picture' in request.FILES:
				print('picture found!')
				profile.picture = request.FILES['picture']

			profile.save()

			registered = True

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

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

	print(registered)	

	return render(request, 'basic_app/registration.html', { 'user_form':user_form,
															'profile_form':profile_form,
															'registered':registered })
Ejemplo n.º 10
0
def register(request):
    #has someone been registered
    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            #save the user information to the database.
            user = user_form.save()
            #HASING the passowrd
            user.set_password(user.password)
            #now saved the hashed PasswordInput
            user.save()

            profile = profile_form.save(commit=False)

            profile.user = user
            #profile_pic is the form field
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profoile_pic']
            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        #set up the form.
        user_form = UserForm()
        profile_form = UserProfileForm()

    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 = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # Saving directly to DB
            user = user_form.save()
            # Hashing pass
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            # Setting the relationship
            profile.user = user

            # checks if provided a profile pic
            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)

    # if request.method == 'GET':
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

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