예제 #1
0
	def test_create_user_function_throws_Integrity_error(self):
		try:
			with trans.atomic(): # Helps fix troubles with databse transaction managment
				User.create('test_user','*****@*****.**','pass','1234','11').save()

		except IntegrityError:
			pass

		else:
			raise Exception('Exception was`t trown') 
예제 #2
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
            # customer = stripe.Charge.create(
            #     description=form.cleaned_data['email'],
            #     card=form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            cd = form.cleaned_data
            try:
                with transaction.atomic():
                    user = User.create(
                        cd['name'],
                        cd['email'],
                        cd['password'],
                        cd['last_4_digits'],
                        stripe_id=''
                    )

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd['email']).save()

            except IntegrityError:
                import traceback
                form.addError(cd['email'] + ' is already a member' + traceback.format_exc())
                user = None
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    return render_to_response(
        'payments/register.html',
        {
            'form': form,
            'months': list(range(1, 12)),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': list(range(2011, 2036)),
        },
        context_instance=RequestContext(request)
    )
예제 #3
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        print form.is_valid()
        if form.is_valid():
            print 'form passed validation'
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan='gold',
            )

            cd = form.cleaned_data

            try:
                user = User.create(cd['name'], cd['email'], cd['password'],
                                   cd['last_4_digits'], customer.id)
            except IntegrityError:
                form.addError(cd['email'] + ' is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')
    else:
        form = UserForm()
    return render_to_response('register.html', {
        'form': form,
        'months': range(1, 12),
        'publishable': settings.STRIPE_PUBLISHABLE,
        'soon': soon(),
        'user': user,
        'years': range(2016, 2036)
    },
                              context_instance=RequestContext(request))
예제 #4
0
    def test_create_user_function_stores_in_database(self):
        """TODO: Docstring for test_create_user_function_stores_in_database.
        :returns: TODO

        """
        user = User.create('test', '*****@*****.**', 'tt', '1234', '22')
        self.assertEqual(User.objects.get(email='*****@*****.**'), user)
예제 #5
0
파일: views.py 프로젝트: Umojivity/main27
def register(request):
    user = None
    if request.method == "POST":
        # We only talk AJAX posts now
        if not request.is_ajax():
            return HttpResponseBadRequest("I only speak AJAX nowadays")

        data = json.loads(request.body.decode())
        form = UserForm(data)

        if form.is_valid():
            try:
                customer = Customer.create(
                    "subscription",
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="gold",
                )
            except Exception as exp:
                form.addError(exp)

            cd = form.cleaned_data
            try:
                with transaction.atomic():
                    user = User.create(cd["name"], cd["email"], cd["password"], cd["last_4_digits"], stripe_id="")

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd["email"]).save()

            except IntegrityError:
                resp = json.dumps({"status": "fail", "errors": cd["email"] + " is already a member"})
            else:
                request.session["user"] = user.pk
                resp = json.dumps({"status": "ok", "url": "/"})

            return HttpResponse(resp, content_type="application/json")
        else:  # form not valid
            resp = json.dumps({"status": "form-invalid", "errors": form.errors})
            return HttpResponse(resp, content_type="application/json")

    else:
        form = UserForm()

    return render_to_response(
        "payments/register.html",
        {
            "form": form,
            "months": list(range(1, 12)),
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "user": user,
            "years": list(range(2011, 2036)),
        },
        context_instance=RequestContext(request),
    )
예제 #6
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            #update based on your billing method (subscription vs one time)
            customer = Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
            # customer = stripe.Charge.create(
            #     description=form.cleaned_data['email'],
            #     card=form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            cd = form.cleaned_data
            from django.db import transaction

            try:
                with transaction.atomic():
                    user = User.create(cd['name'], cd['email'], cd['password'],
                                       cd['last_4_digits'], stripe_id="")

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd['email']).save()

            except IntegrityError:
                import traceback
                form.addError(cd['email'] + ' is already a member' +
                              traceback.format_exc())
                user = None
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    return render_to_response(
        'payments/register.html',
        {
            'form': form,
            'months': list(range(1, 12)),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': list(range(2011, 2036)),
        },
        context_instance=RequestContext(request)
    )
예제 #7
0
    def test_create_user_function_stores_in_database(self):
        """
        Tests User.create method
        """
        new_user = User.create('jean', '*****@*****.**', 'password',
                               '1234', '1')
        test = User.objects.get(email='*****@*****.**')

        self.assertEquals(test, new_user)
예제 #8
0
 def test_create_user_already_exists_throws_IntegrityError(self):
     self.assertRaises(
         IntegrityError, 
         User.create(
         "test user",
         "*****@*****.**",
         "jj",
         "1234",
         89
         )
     )
예제 #9
0
def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            if form.cleaned_data["sub_type"] == "monthly":
                # update based on your billing method(subscription vs onetime)
                customer = Customer.create(
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="gold",
                )
            else:
                customer = Customer.create(
                    email=form.cleaned_data["email"],
                    description=form.cleaned_data["name"],
                    card=form.cleaned_data["stripe_token"],
                    plan="Platinum",
                )

            cd = form.cleaned_data
            try:
                with transaction.atomic():
                    user = User.create(cd["name"], cd["email"], cd["password"], cd["last_4_digits"])

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd["email"]).save()

            except IntegrityError:
                form.addError(cd["email"] + " is already a member")
            else:
                request.session["user"] = user.pk
                return HttpResponseRedirect("/")

    else:
        form = UserForm()

    return render_to_response(
        "payments/register.html",
        {
            "form": form,
            "months": list(range(1, 12)),
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "user": user,
            "years": list(range(2011, 2036)),
        },
        context_instance=RequestContext(request),
    )
예제 #10
0
def register(request):
	user = None
	if request.method == 'POST':
		form = UserForm(request.POST)
		if form.is_valid():
			#update based on your billing method (subscription vs one time)

			customer = stripe.Customer.create(
				email=form.cleaned_data['email'],
				description=form.cleaned_data['name'],
				card=form.cleaned_data['stripe_token'],
				plan='gold',
			)

			#customer = stripe.Charge.create(
			#	description = form.cleaned_data['email'] 
			#	card=form.cleaned_data['stripe_token'],
			#	amount="5000",
			#	currency="usd"
			#)

			
			cd = form.cleaned_data
			try:
				user = User.create(
					cd['name'],
					cd['email'],
					cd['password'],
					cd['last_4_digits'],
					customer.id
				)

			except IntegrityError:
				form.addError(user.email + ' is already a member')
				user = None
			else:
				request.session['user'] = user.pk
				return HttpResponseRedirect('/')
	else:
		form = UserForm()

	return render_to_response(
		'register.html',
		{
			'form':form,
			'months':range(1,12),
			'publishable': settings.STRIPE_PUBLISHABLE,
			'soon':soon(),
			'user':user,
			'years':range(2011, 2036),
		},
		context_instance=RequestContext(request)
	)
예제 #11
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            #update based on billing method (subscrip vs one time[add appropriate code for one time])
            customer = Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
            
            cd = form.cleaned_data
            try:
                user = User.create(
                    cd['name'],
                    cd['email'],
                    cd['password'],
                    cd['last_4_digits'],
                    customer.id
                )
            except IntegrityError:
                form.addError(cd['email'] + ' is already a member')
                user = None
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    return render_to_response(
        'register.html',
        {
            'form': form,
            'months': list(range(1, 12)),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': list(range(2011, 2036)),
        },
        context_instance=RequestContext(request)
    )
예제 #12
0
def post_user(request):
    form = UserForm(request.data)

    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

        cd = form.cleaned_data
        try:
            with transaction.atomic():
                user = User.create(cd['name'],
                                   cd['email'],
                                   cd['password'],
                                   cd['last_4_digits'],
                                   stripe_id='')

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()

        except IntegrityError:
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
예제 #13
0
def post_user(request):
    form = UserForm(request.DATA)

    print("in post user")
    if form.is_valid():
        try:
            # update based on your billing method (subscription vs one time)
            customer = Customer.create(
                "subscription",
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )
        except Exception as exp:
            form.addError(exp)

        cd = form.cleaned_data
        try:
            with transaction.atomic():
                user = User.create(
                    cd['name'], cd['email'],
                    cd['password'], cd['last_4_digits'])

                if customer:
                    user.stripe_id = customer.id
                    user.save()
                else:
                    UnpaidUsers(email=cd['email']).save()
        except IntegrityError as e:
            print("----------Integristy error")
            print(e)
            form.addError(cd['email'] + ' is already a member')
        else:
            request.session['user'] = user.pk
            resp = {"status": "ok", "url": '/'}
            return Response(resp, content_type="application/json")

        resp = {"status": "fail", "errors": form.non_field_errors()}
        return Response(resp)
    else:  # for not valid
        resp = {"status": "form-invalid", "errors": form.errors}
        return Response(resp)
예제 #14
0
def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data["email"],
                description=form.cleaned_data["name"],
                card=form.cleaned_data["stripe_token"],
                plan="gold",
            )
            # customer = stripe.Charge.create(
            #     description = form.cleaned_data['email'],
            #     card = form.cleaned_data['stripe_token'],
            #     amount = "5000",
            #     currency="usd"
            # )

            cd = form.cleaned_data
            try:
                user = User.create(cd["name"], cd["email"], cd["password"], cd["last_4_digits"], customer.id)
            except IntegrityError:
                form.addError(cd["email"] + " is already a member")
            else:
                request.session["user"] = user.pk
                return HttpResponseRedirect("/")
    else:
        form = UserForm()

    return render_to_response(
        "register.html",
        {
            "form": form,
            "months": range(1, 12),
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "user": user,
            "years": range(2011, 2036),
        },
        context_instance=RequestContext(request),
    )
예제 #15
0
 def setUp(self):
     self.valid_test_user = User.create("tester",
                                        "*****@*****.**",
                                        "test",
                                        1234)
     self.sign_in_page = SignInPage(self.browser, self.live_server_url)
예제 #16
0
 def setUpTestData(cls):
     cls.test_user = User.create(email="*****@*****.**", name='test user',
                                 password="******", last_4_digits="1234")
예제 #17
0
 def test_create_user_function_stores_in_database(self):
     user=User.create('test','*****@*****.**','tt','1234','22')
     self.assertEquals(User.objects.get(email='*****@*****.**'),user)
예제 #18
0
	def setUp(self):
		self.test_user = User.create('test_user','*****@*****.**','pass','1234','11')
		self.test_user.save()
예제 #19
0
 def test_create_user_function_stores_in_database(self):
     user = User.create("test", "*****@*****.**", "tt", "1234", "22")
     self.assertEquals(User.objects.get(email="*****@*****.**"), user)
예제 #20
0
 def test_create_user_function_stores_in_database(self):
     user = User.create("test", "*****@*****.**","tt","1234","22")
     self.assertEqual(User.objects.get(email="*****@*****.**"), user)
예제 #21
0
 def setUp(self):
     self.valid_test_user = User.create("tester", "*****@*****.**", "test",
                                        1234)
     self.sign_in_page = SignInPage(self.browser, "http://" + SERVER_ADDR)
예제 #22
0
 def setUpClass(cls):
     super(UserModelTest,cls).setUpClass()
     cls.test_user=User.create(email='*****@*****.**', name='test user',
     password="******",last_4_digits="1234")
예제 #23
0
def register(request):

	user = None
	if request.method == 'POST':

		form = UserForm(request.POST)

		if form.is_valid():
			
			cd = form.cleaned_data

			#Create stripe user with subscription plan
			cd['plan'] = 'gold'
			cd['payment_type'] = 'subscription'
			customer = CustomerManager.stripe_create(**cd)
			#To change subscription plan to single paymants
			# comment line abowe and uncomment lines below

			#cd['amount'] = "5000"
			#cd['currency'] = "usd"
			#customer = stripe_create('single', cd)

			
			try:
				with transaction.atomic():
					user = User.create(
							cd['name'],
							cd['email'],
							cd['password'],
							cd['last_4_digits'],
							stripe_id=''
						)

					# if stripe is working, add stripe id
					if customer:
						user.stripe_id = customer.id
						user.save()
					else:
						UnpaidUsers(email=cd['email']).save()

			except IntegrityError:
				form.addError(cd['email'] + ' is already a member')

			else:
				request.session['user'] = user.pk
				return HttpResponseRedirect('/')

	else:
		form = UserForm()

	return render_to_response(
			'payments/register.html',
			{
				'form':form,
				'months': list(range(1,13)),
				'publishable' : settings.STRIPE_PUBLISHABLE,
				'soon':soon(),
				'user':user,
				'years':list(range(2014, 2036)),
			},
			context_instance=RequestContext(request)
		)
예제 #24
0
 def setUpClass(cls):
     cls.test_user = User.create(email="*****@*****.**",
                                 name='test user',
                                 password="******",
                                 last_4_digits="1234")
예제 #25
0
def register(request):
    user = None
    if request.method == 'POST':
        # We only talk AJAX posts now
        if not request.is_ajax():
            return HttpResponseBadRequest("I only speak AJAX nowadays")

        data = json.loads(request.body.decode())
        form = UserForm(data)

        if form.is_valid():
            try:
                customer = Customer.create(
                    "subscription",
                    email=form.cleaned_data['email'],
                    description=form.cleaned_data['name'],
                    card=form.cleaned_data['stripe_token'],
                    plan="gold",
                )
            except Exception as exp:
                form.addError(exp)

            cd = form.cleaned_data
            try:
                with transaction.atomic():
                    user = User.create(cd['name'],
                                       cd['email'],
                                       cd['password'],
                                       cd['last_4_digits'],
                                       stripe_id="")

                    if customer:
                        user.stripe_id = customer.id
                        user.save()
                    else:
                        UnpaidUsers(email=cd['email']).save()

            except IntegrityError:
                resp = json.dumps({
                    "status":
                    "fail",
                    "errors":
                    cd['email'] + ' is already a member'
                })
            else:
                request.session['user'] = user.pk
                resp = json.dumps({"status": "ok", "url": '/'})

            return HttpResponse(resp, content_type="application/json")
        else:  # form not valid
            resp = json.dumps({
                "status": "form-invalid",
                "errors": form.errors
            })
            return HttpResponse(resp, content_type="application/json")

    else:
        form = UserForm()

    return render_to_response('payments/register.html', {
        'form': form,
        'months': list(range(1, 12)),
        'publishable': settings.STRIPE_PUBLISHABLE,
        'soon': soon(),
        'user': user,
        'years': list(range(2011, 2036)),
    },
                              context_instance=RequestContext(request))
예제 #26
0
 def setUp(self):
     self.valid_test_user = User.create(
         "tester", "*****@*****.**", "test", 1234)
     self.sign_in_page = SignInPage(self.browser, "http://"+SERVER_ADDR)