def register(request):
    registered = False

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

    return render(
        request, 'basicapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
        })
Example #2
0
def superAdmin(request):

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        institute_form = InstituteProfileInfoForm(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_name = user

            profile.save()

            institute = institute_form.save(commit=False)
            institute.user_name = user
            institute.save()

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

    return render(
        request, 'basicapp/superAdmin.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'institute_form': institute_form
        })
Example #3
0
def register(request):

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

            register = True

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

    return render(request, "basicapp/registration.html", {
        "user_form": user_form,
        "profile_form": profile_form,
        "register": register
    })
Example #4
0
def addUser(request):
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        add_user_form = addUserForm(data=request.POST)

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

            profile = add_user_form.save(commit=False)
            profile.user_name = user
            profile.access_type = 'NormalUser'
            profile.save()

        else:
            print(user_form.errors, add_user_form.errors)
    else:
        user_form = UserForm()
        add_user_form = addUserForm()

    return render(request, 'basicapp/adduser.html', {
        'user_form': user_form,
        'add_user_form': add_user_form
    })
Example #5
0
def register(req):
    registered = False
    if (req.method == 'POST'):
        userform = UserForm(data=req.POST)
        profileform = UserProfile(data=req.POST)
        if (userform.is_valid() and profileform.is_valid()):
            user = userform.save()
            user.set_password(user.password)
            user.save()
            Profile = profileform.save(commit=False)
            Profile.user = user
            if ('profile_pic' in req.FILES):
                Profile.profile_pic = req.FILES['profile_pic']
            Profile.save()
            registered = True
            print(register)
        else:
            print("ERROR")
    else:
        userform = UserForm()
        profileform = UserProfile()
    return render(req, "basicapp/register.html", {
        'registered': registered,
        'userform': userform,
        'profileform': profileform
    })
def register(request):

    registered = False

    if request.method == 'POST':

        #  assigning one variable to take values from the forms
        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()
            # for to go in settings to user password hashing
            user.set_password(user.password)
            user.save()
            #This is main where profile variable is taking data from both and saving it in database, where we used one attribute in UserProfileInfoForm user to add the additional
            # form details to default user buitin from django, to save the details from user form to user model profile.user to assign to attributes of user database
            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, 'basicapp/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)  #hashing of password is done here
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user  #used for OneToOne mapping with User Model

            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, "basicapp/registration.html", {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #8
0
def register(request):

    #registered=False

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

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

            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.is_active = False  #User cant login without email conformation
            user.save()

            #Email verification activity starts
            current_site = get_current_site(
                request
            )  #It checks if current site is present in domain or not
            mail_subject = 'Activate your account'  #Subject of the mail that we are sending
            message = render_to_string(
                'basicapp/acc_active_email.html',
                {
                    'user':
                    user,  #Email message created by a template acc_active_email.html this template creates email body with activation link that will send for application
                    'domain': current_site.
                    domain,  # domain-type in a web address, e.g., www.jimsbikes.com, your Internet Service Provider views the DNS associated with the domain name, translates it into a machine friendly IP address (for example 216.168.224.70 is the IP for jimsbikes.com) and directs your Internet connection to the correct website.
                    'uid': urlsafe_base64_encode(
                        force_bytes(user.pk)
                    ),  #encodes a byte string in base64 for use in URL,stripping any trailing equal signs &&&&& and user.pk gives user.id
                    'token': account_activation_token.make_token(user)
                })
            to_email = user_form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message,
                                 to=[to_email])  #creating email message
            email.send()  #Sending Email
            print("Email Sent")

            #views for user_profile_info
            profile = profile_form.save(commit=False)
            profile.user = user  #Since it has OneToOne relationship.Mentioned in the models
            if "profile_pic" in request.FILES:
                profile.profile_pic = request.FILES["profile_pic"]
            profile.save()
            #views for user profile info ends here

            return render(request, "basicapp/confirm_email.html")

            #registered=True

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

    return render(request, "basicapp/registration.html", {
        "user_form": user_form,
        "profile_form": profile_form
    })
Example #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():

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

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            registered = True
            return render(request, 'registration/scc_register.html')
        else:
            print(user_form.errors, profile_form.errors)

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

    return render(
        request, 'registration/register.html/', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #10
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, 'basicapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #11
0
def registration(request):
    registered = False

    if request.method == "POST":
        # Is POST Method
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

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

            #process user form
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            #process user profile forms
            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:
        # Not POST Method
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # return render(request,'basicapp/registration.html', context={'name':'registration',
    #                                                     'user_form': user_form,
    #                                                     'profile_form': profile_form,
    #                                                     'registered': registered
    #                                                })
    if registered:
        return HttpResponseRedirect(reverse('user_login'))
    else:
        return render(request,
                      'basicapp/registration.html',
                      context={
                          'name': 'registration',
                          'user_form': user_form,
                          'profile_form': profile_form,
                          'registered': registered
                      })
def register(request):
    registered = False

    if request.method == 'POST':
        #Create objects of type form
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        #Check if the data entered is valid and then perform any action
        if user_form.is_valid() and profile_form.is_valid():
            #Variable USER which is an object of the instance UserForm saves the data submitted thru the form
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            #Check above as with USER. PROFILE is an object of type UserProfileInfoForm and has all the data submitted to the form inside and we can work with that data now.

            profile = profile_form.save(commit=False)

            #We can access USER with PROFILE, because PROFILE inharetes USER. Profile.User = User means that all data plus the new one will be saved.
            profile.user = user

            #Saving the picture uploaded by the user to the database

            if 'profile_pic' in request.FILES:
                profile_pic = request.FILES('profile_pic')

            profile.save()

            registered = True

        else:
            #Print registration errors
            print(user_form.errors, profile_form.errors)

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

    #Return the information acquired as dictionary to a template
    return render(
        request, 'basicapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #13
0
File: views.py Project: dish34/Quiz
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, 'basicapp/register.html', {
        'user_form': user_form,
        'registered': registered
    })
Example #14
0
def register(request):

	registered=False

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

	    

	        # One of the forms was invalid if this else gets called.
	        

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

	# This is the render and context dictionary to feed
	# back to the registration.html file page.
	return render(request,'basicapp/registration.html',
	                      {'user_form':user_form,
	                       'profile_form':profile_form,
	                       'registered':registered})
def register(request):
    registered = False

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

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

            user = user_form.save()
            user.set_password(
                user.password
            )  # Sets the password as a Hash byb going into settings.py
            user.save()  #Saved the hashed password to the database

            profile = profile_form.save(
                commit=False
            )  #dont want to commit to the database yet otherwise may encounter collisions where the user will be overwritten
            profile.user = user  # SETS UP ONE TO ONE RELATIONSHIP

            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, 'basicapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
def register(request):

    #checking if the user is registered or not
    registered = False

    if request.method == "POST":
        #grabbing the info off the forms
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        #checking if all the forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            #if the forms are valid, we grab info from the user form
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            #grabbing info from the profile form
            profile = profile_form.save(commit = False)

            #this line reperesents the one to one relationship bw the user and profile form
            profile.user = user

            #double checking if there is a picture in there before savinf
            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:
        #if the request is not POST then creating the instances of user form and profile form
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(request,'basicapp/registration.html',
        {'user_form':user_form,'profile_form':profile_form,'registered':registered})
Example #17
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(
            )  # in case we want to save that info directly to database
            user.set_password(user.password)
            user.save()

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

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

            profile.save()
            registered = True

        else:
            print(user_form.errors, profile_form)

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

    return render(request,
                  'basicapp/registration.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered,
                  })
Example #18
0
def register(request):
    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()
            return HttpResponseRedirect(reverse('basicapp:login'))
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
        return render(request, 'basicapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form
        })
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('Profile Pic Found')
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

            print("User {} Registration Successful".format(
                request.POST.get('username')))
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

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