Example #1
0
def register(request):
    if (request.user.is_authenticated()):
        
        return HttpResponseRedirect('/tooldirectory/') 
    if request.method == 'POST': 					# If the form has been submitted...
        form = RegistrationForm(request.POST) 		# A form bound to the POST data
        if form.is_valid(): 						# All validation rules pass
            fName = form.cleaned_data['firstName']
            lName = form.cleaned_data['lastName'] 
            username = form.cleaned_data['username']
            pwd = form.cleaned_data['password']
            email = form.cleaned_data['email']
            sAddress = form.cleaned_data['streetAddress']
            city = form.cleaned_data['city']
            state = form.cleaned_data['state']
            zcode = form.cleaned_data['zipcode']     

            # Tries to create a new user and add them to the database
            try:
                u = User.objects.create_user(username, email=email, password=pwd, first_name=fName, last_name=lName)
                UserProfile.create(u,zcode,sAddress,state,city).save()  # Saves new user to database
            except:
                #Add error
                return HttpResponseRedirect('#ERROR') 
            return HttpResponseRedirect('/login/') 	# Redirect after POST
    else:
        form = RegistrationForm() 					# An unbound form

    return render(request, 'registration/register.html', {'form': form})
    
    
Example #2
0
def register(request):
    if (request.user.is_authenticated()):

        return HttpResponseRedirect('/tooldirectory/')
    if request.method == 'POST':  # If the form has been submitted...
        form = RegistrationForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            fName = form.cleaned_data['firstName']
            lName = form.cleaned_data['lastName']
            username = form.cleaned_data['username']
            pwd = form.cleaned_data['password']
            email = form.cleaned_data['email']
            sAddress = form.cleaned_data['streetAddress']
            city = form.cleaned_data['city']
            state = form.cleaned_data['state']
            zcode = form.cleaned_data['zipcode']

            # Tries to create a new user and add them to the database
            try:
                u = User.objects.create_user(username,
                                             email=email,
                                             password=pwd,
                                             first_name=fName,
                                             last_name=lName)
                UserProfile.create(u, zcode, sAddress, state,
                                   city).save()  # Saves new user to database
            except:
                #Add error
                return HttpResponseRedirect('#ERROR')
            return HttpResponseRedirect('/login/')  # Redirect after POST
    else:
        form = RegistrationForm()  # An unbound form

    return render(request, 'registration/register.html', {'form': form})
Example #3
0
 def test_invalid_six(self):
     form_data = {
         'name': 'John Doe',
         'organization': 'Company SA',
         'country': 'XX',
         'email': '*****@*****.**'
     }
     form = RegistrationForm(data=form_data)
     self.assertFalse(form.is_valid())
Example #4
0
 def test_valid_five(self):
     form_data = {
         'name': '',
         'organization': 'Company',
         'country': 'CH',
         'email': '*****@*****.**'
     }
     form = RegistrationForm(data=form_data)
     self.assertFalse(form.is_valid())
Example #5
0
def homepage(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_regist = form.save(commit=False)
            doctor = form.cleaned_data['doctor']
            date = form.cleaned_data['date']
            time = form.cleaned_data['time']
            client = form.cleaned_data['client']
            new_regist = form.save()
            return HttpResponseRedirect('/')
    else:
        form = RegistrationForm()
    return render(request, 'home.html', {'form': form})
Example #6
0
def AccountRegistration(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile')
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(username=form.cleaned_data['username'], email=form.cleaned_data['email'],
                password=form.cleaned_data['password'])
            user.save()
            account = UserProfile(user=user)

            account.save()
            return HttpResponseRedirect('/registration/ok/')
        else:
            return render_to_response('register.html', {'form':form}, context_instance = RequestContext(request))
    else:
        ''' pusty formularz '''
        form = RegistrationForm()
        context ={'form': form}
        return render_to_response('register.html', context, context_instance = RequestContext(request))
Example #7
0
 def test_valid_seven(self):
     form_data = {'name': '', 'organization': '', 'country': '', 'email': ''}
     form = RegistrationForm(data=form_data)
     self.assertFalse(form.is_valid())