Example #1
0
def register(request):
    registered = False
    if request.method == 'POST':
        userform = UserForm(request.POST)
        userprofileform = UserProfileForm(request.POST)
        if userform.is_valid() and userprofileform.is_valid():
            user = userform.save()
            user.set_password(user.password)
            user.save()
            userprofile = userprofileform.save(commit=False)
            userprofile.user = user
            if 'picture' in request.FILES:
                userprofile.picture = request.FILES.get('picture')
            userprofile.save()
            registered = True
            return redirect('/watchfilm/login/')
        else:
            print userform.errors, userprofileform.errors
    else:
        userform = UserForm()
        userprofileform = UserProfileForm()
    return render(
        request, 'watchfilm/register.html', {
            'registered': registered,
            'userform': userform,
            'userprofileform': userprofileform
        })
Example #2
0
def register(request):
    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False
    # If it's a HTTP POST, we're interested in processing form data
    if request.method == 'POST':

        # Attempt to grab information from the form information
        # Note that we make use of both UserForm and UserProfileForm

        user_form = UserForm(data=request.POST)
        user_profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid

        if user_form.is_valid() and user_profile_form.is_valid():
            # Save the user form data to database
            user = user_form.save()

            # Now we hash the password with the set_password method
            # Once hashed, we can update the user object

            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance
            # Since we need to set the user attribute ourselves, we set commit=False
            # This delays saving the model until we're ready to avoid integrity problems
            profile = user_profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            # Now we save the UserProfile model instance
            profile.save()

            # Update our variable to tell the template registration was successful
            registered = True

        # Invalid form or forms-mistakes or something else?
        # Print problems to the terminals
        # They will also be shown to the user
        else:
            print user_form.errors, user_profile_form.errors
    # Not a HTTP POST so we render our form using two ModelForm instances
    # These forms will be blank, ready for user input

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

    # Render the template depending on the context
    return render(
        request, 'registration.html', {
            'user_form': user_form,
            'user_profile_form': user_profile_form,
            'registered': registered
        })
Example #3
0
def register(request):

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    if request.session.test_cookie_worked():
        print ">>>> TEST COOKIE WORKED!"
        request.session.delete_test_cookie()

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(request,
            'rango/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered} )
Example #4
0
File: views.py Project: grv07/clat
def user_action(request):
	post_req_data = request.POST
	# print post_req_data
	data = {}
	user_form = UserForm(data=request.POST)
	register_form = StudentRegistrationForm(data=post_req_data)
	student_model = StudentModel(data=post_req_data)
	if  user_form.is_valid() and register_form.is_valid():
		try:
			if student_model.is_valid():
				address_model = AddressModel(data=post_req_data)
				if address_model.is_valid():
					try:
						city = City.objects.get(city_name = post_req_data.get('city', ''))
						assert city,'AssertError: city not found in database'
						address = address_model.save(commit = False)
						address.city_obj = city
						address.save()
					except Exception as e:
						logger.error('under student.view.user_action '+str(e.args))
						messages.error(request,'Error when trying to create the user. Please try again.')
						data = {'form': register_form,'register_error':True,'value_state':post_req_data.get('state', ''),'value_city':post_req_data.get('city', ''),'mailing_addr':post_req_data.get('mailing_address', '')}
						return render(request, 'register.html', data)

					try:
						user = user_form.save()
						# print user.password
						user.set_password(user.password)
						user.email = post_req_data.get('email',None)
						# print user.email
						user.save()
						import uuid
						student = student_model.save(commit=False)
						student.student = user           
						student.address = address
						student.uuid_key = 'eq' + str(uuid.uuid4().fields[-1])[:8]
						student_pass = post_req_data.get('password',None)
						student.gender = post_req_data.get('gender',None)
						p_date = post_req_data.get('d_o_b',None)
						
						if p_date:
							import datetime
							d_o_b = datetime.datetime.strptime(p_date, '%m/%d/%Y').date()
							student.d_o_b = d_o_b
						else:
							pass
						student.higher_education = post_req_data.get('higher_education',None)
						student.i_agree = post_req_data.get('i_agree')
						student.save()
						kawrgs = {'student_pass' : student_pass,'student_uname' : user.username,'phone_number' : student.phone_number, 'full_name' : student.full_name, 'uuid_key' : student.uuid_key}
						verification_mail(user = user.id,domain = request.META['HTTP_HOST'],**kawrgs)
						return user_actions.login_user(request)
					except Exception as e:
						logger.error('under student.view.user_action '+str(e.args))
				else:
					data = {'form': address_model,'register_error':True,'value_state':post_req_data.get('state', ''),'value_city':post_req_data.get('city', ''),'mailing_addr':post_req_data.get('mailing_address', '')}
			else:
				data = {'form': student_model,'register_error':True , 'value_state':post_req_data.get('state', ''),'value_city':post_req_data.get('city', ''),'mailing_addr':post_req_data.get('mailing_address', '')}
		
		except Exception as e:
			logger.error('under student.view.user_action '+str(e.args))
	else:
		messages.error(request,'Error when trying to create the User.')
		data = {'form': register_form,'register_error':True,'value_state':post_req_data.get('state', ''),'value_city':post_req_data.get('city', ''),'mailing_addr':post_req_data.get('mailing_address', '')}
	return render(request, 'register.html', data)