Ejemplo n.º 1
0
 def test_anonymous_user(self):
     """
     This needs to throw an ImproperlyConfigured error so the developer
     can be guided to properly protect the subscription content.
     """
     anon_user = AnonymousUser()
     with self.assertRaises(ImproperlyConfigured):
         subscriber_has_active_subscription(anon_user)
Ejemplo n.º 2
0
 def test_anonymous_user(self):
     """
     This needs to throw an ImproperlyConfigured error so the developer
     can be guided to properly protect the subscription content.
     """
     anon_user = AnonymousUser()
     with self.assertRaises(ImproperlyConfigured):
         subscriber_has_active_subscription(anon_user)
Ejemplo n.º 3
0
def file(request, file_hash):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	user_file = UserFile.objects.get(hash=file_hash) #saving this model instance to var

	expire_time = user_file.pub_date + datetime.timedelta(minutes=user_file.expire)
	now = datetime.datetime.now(timezone.utc) #getting current time
	p = user_file.password
	current_user = request.user
	file_user = user_file.user_name
	if p: 
		if request.session.get(user_file.hash):
			return redirect('destructible.views.passwordprotected', file_hash=user_file.hash)
		form = UserFileForm()
		return render(request, 'destructible/password_required.html', {'form': form, 'user_file': user_file, 'is_active': is_active})
	else:
	
		if expire_time >= now:

			user_file = get_object_or_404(UserFile, hash=file_hash)
			current_user = request.user.get_username()
			file_uploader_name = user_file.user_name
			if (current_user) == (file_uploader_name): #tests if user who uploaded is current user
				return render(request, 'destructible/authuploaded.html', {"user_file": user_file, 'is_active': is_active}) #returns template w/ add'l option		
			else:
				return render(request, 'destructible/uploaded.html', {"user_file": user_file, 'is_active': is_active})
		else:
			return redirect('destructible.views.expire_now', uuid=user_file.uuid)
Ejemplo n.º 4
0
    def test_user_has_active_subscription(self):
        subscription = Subscription.sync_from_stripe_data(deepcopy(FAKE_SUBSCRIPTION))
        subscription.current_period_end = timezone.now() + timezone.timedelta(days=10)
        subscription.save()

        # Assert that the customer's subscription is valid
        self.assertTrue(subscriber_has_active_subscription(self.user))
Ejemplo n.º 5
0
def text(request):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	if request.method == 'POST':
		fform = NoAuthUserFileForm(request.POST) #unregistered user
		nform = NoAuthUploadForm(request.POST, request.FILES) #smaller file size, one file only
			
		if fform.is_valid() and nform.is_valid():

			f = UserFile() 
			file_hash = human_readable_hash()
		
			f.hash = file_hash
			f.expire = fform.cleaned_data['expire']
			f.max_expire = 65
			f.save()
			
			docfile = Attachment(docfile = request.FILES['docfile'], userfile=f).save()
			
		return redirect('destructible.views.file', file_hash=f.hash)	
		
	else:
		aform = ActiveUploadForm()
		eform = ActiveUserFileForm()
	return render(request, "destructible/text.html", {'is_active': is_active})
Ejemplo n.º 6
0
def email(request):
	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	if request.method == 'GET':
		contactform = ContactForm()
	else:
		contactform = ContactForm(request.POST)
		c = Contact()
		if contactform.is_valid():
			subject = contactform.cleaned_data['subject']
			from_email = contactform.cleaned_data['from_email']
			message = contactform.cleaned_data['message']
			c.subject = subject
			c.from_email = from_email
			c.message = message
			c.save()
			try:
				send_mail(subject, message, from_email, ['*****@*****.**'])
			except BadHeaderError:
				return HttpResponse('Invalid header found.')
			return redirect('thanks')
	return render(request, "destructible/email.html", {'contactform': contactform, 'is_active': is_active})
Ejemplo n.º 7
0
def moreinfo(request):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	return render(request, "destructible/moreinfo.html", {'is_active': is_active})
Ejemplo n.º 8
0
def userfilelist(request):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	current_user = request.user.username
	user_file = UserFile.objects.filter(user_name=current_user)

	return render(request, 'destructible/filelist.html', {'user_file': user_file, 'is_active': is_active})
		
Ejemplo n.º 9
0
def expire_now(request, uuid):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	user_file = get_object_or_404(UserFile, uuid=uuid)

	time_to_delete = user_file.attachment_set.all()
	
	for entry in time_to_delete:
		entry.docfile.delete()
	
	user_file.delete()
	return redirect('/destructible/expired.html', {'is_active': is_active})
Ejemplo n.º 10
0
    def test_user_has_active_subscription(self):
        # Make the customer have an active subscription
        period_start = datetime.datetime(2013, 4, 1, tzinfo=timezone.utc)
        period_end = datetime.datetime(2013, 4, 30, tzinfo=timezone.utc)

        # Start 'em off'
        start = datetime.datetime(2013, 1, 1, 0, 0, 1)  # more realistic start
        CurrentSubscription.objects.create(customer=self.customer,
                                           plan="test",
                                           current_period_start=period_start,
                                           current_period_end=period_end,
                                           amount=(500 /
                                                   decimal.Decimal("100.0")),
                                           status="active",
                                           start=start,
                                           quantity=1)

        # Assert that the customer's subscription is action
        self.assertTrue(subscriber_has_active_subscription(self.user))
Ejemplo n.º 11
0
    def test_user_has_active_subscription(self):
        # Make the customer have an active subscription
        period_start = datetime.datetime(2013, 4, 1, tzinfo=timezone.utc)
        period_end = datetime.datetime(2013, 4, 30, tzinfo=timezone.utc)

        # Start 'em off'
        start = datetime.datetime(2013, 1, 1, 0, 0, 1)  # more realistic start
        CurrentSubscription.objects.create(
            customer=self.customer,
            plan="test",
            current_period_start=period_start,
            current_period_end=period_end,
            amount=(500 / decimal.Decimal("100.0")),
            status="active",
            start=start,
            quantity=1
        )

        # Assert that the customer's subscription is action
        self.assertTrue(subscriber_has_active_subscription(self.user))
Ejemplo n.º 12
0
def password_required(request, file_hash):

	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
		
	if request.method == 'POST':
		form = UserFileForm(request.POST)
		
		p = form.data['password']
		user_file = get_object_or_404(UserFile, hash=file_hash)
		up = user_file.password
		if up == p:
			#implement set cookie here
			request.session[user_file.hash] = True
			return redirect('destructible.views.passwordprotected', file_hash=user_file.hash)			#return render('destructible.views.file', file_hash=f.hash)
		else:
			return render(request, 'destructible/password_required.html', {'form': form, 'user_file': user_file, 'is_active': is_active})
	else:
		form = UserFileForm()
		return render(request, 'destructible/password_required.html', {'form': form, 'user_file': user_file, 'is_active': is_active})
Ejemplo n.º 13
0
def is_premium(user, account):
    if account.sponsored:
        return True
    else:
        return subscriber_has_active_subscription(user)
Ejemplo n.º 14
0
    def test_superuser(self):
        self.user.is_superuser = True
        self.user.save()

        self.assertTrue(subscriber_has_active_subscription(self.user))
Ejemplo n.º 15
0
 def test_user_has_inactive_subscription(self):
     self.assertFalse(subscriber_has_active_subscription(self.user))
Ejemplo n.º 16
0
 def has_active_subscription(self):
     return subscriber_has_active_subscription(self)
Ejemplo n.º 17
0
 def test_user_has_inactive_subscription(self):
     self.assertFalse(subscriber_has_active_subscription(self.user))
Ejemplo n.º 18
0
 def has_active_subscription(self):
     """Checks if a user has an active subscription."""
     return subscriber_has_active_subscription(self)
Ejemplo n.º 19
0
def fileList(request):
	
	if request.user.is_authenticated():
		is_active = subscriber_has_active_subscription(request.user)
	else:
		is_active = False
	
	def human_readable_hash():
		adj = open(os.path.join(settings.PROJECT_ROOT, 'adjlist.txt'))
		noun = open(os.path.join(settings.PROJECT_ROOT, 'nounlist.txt'))
		adjwords = [line.strip() for line in adj]
		nounwords = [line.strip() for line in noun]
		return ''.join(random.choice(adjwords) + random.choice(adjwords) + random.choice(nounwords))
	contactform = ContactForm(request.POST)
	c = Contact()
	
	if is_active:
		if request.method == 'POST':
			eform = ActiveUserFileForm(request.POST) #paid user
			aform = ActiveUploadForm(request.POST, request.FILES)
			
			if eform.is_valid() and aform.is_valid():

				f = UserFile() 
				file_hash = human_readable_hash()

				if eform.data['hash']:
					f.hash = eform.data['hash']
				else:
					f.hash = file_hash
						
				f.expire = eform.cleaned_data['expire']
				f.max_expire = 1440
				f.password = eform.cleaned_data['password']
				f.user_name = request.user.username
				f.save()
					
				for afile in request.FILES.getlist('docfile'):
					Attachment(docfile=afile, userfile=f).save()
					
				return redirect('destructible.views.file', file_hash=f.hash)

		else:
			aform = ActiveUploadForm()
			eform = ActiveUserFileForm()
			
		return render(request, 'destructible/file.html', {'eform': eform, 'aform': aform, 'is_active': is_active})

	elif request.user.is_authenticated():
		if request.method == 'POST':
			form = UserFileForm(request.POST) #registered, not paid
			uform = UploadForm(request.POST, request.FILES) #auth/active user form, multi files
			
			if form.is_valid() and uform.is_valid():

				f = UserFile() 
				file_hash = human_readable_hash()
		
				if form.data['hash']:
					f.hash = form.data['hash']
				else:
					f.hash = file_hash
						
				f.expire = form.cleaned_data['expire']
				f.max_expire = 130
				f.user_name = request.user.username
				f.save()
					
				for afile in request.FILES.getlist('docfile'):
					Attachment(docfile=afile, userfile=f).save()
					
				return redirect('destructible.views.file', file_hash=f.hash)

		else:
			form = UserFileForm()
			uform = UploadForm()
			
		return render(request, 'destructible/file.html', {'form': form, 'uform': uform, 'is_active': is_active})

	else:
	
		if request.method == 'POST':
			fform = NoAuthUserFileForm(request.POST) #unregistered user
			nform = NoAuthUploadForm(request.POST, request.FILES) #smaller file size, one file only
			
			if fform.is_valid() and nform.is_valid():

				f = UserFile() 
				file_hash = human_readable_hash()
		
				f.hash = file_hash
				f.expire = fform.cleaned_data['expire']
				f.max_expire = 65
				f.save()
				docfile = Attachment(docfile = request.FILES['docfile'], userfile=f).save()
				return redirect('destructible.views.file', file_hash=f.hash)

		else:
			nform = NoAuthUploadForm()
			fform = NoAuthUserFileForm()
			
		return render(request, 'destructible/file.html', {'fform': fform, 'nform': nform, 'is_active': is_active, 'contactform': contactform})
Ejemplo n.º 20
0
    def test_staff_user(self):
        self.user.is_staff = True
        self.user.save()

        self.assertTrue(subscriber_has_active_subscription(self.user))
Ejemplo n.º 21
0
 def has_active_subscription(self):
     """Checks if a user has an active subscription."""
     return subscriber_has_active_subscription(self.user)