Make stuff a little prettier

This commit is contained in:
Kumi 2020-10-24 16:50:04 +02:00
parent 3076ab1ad4
commit 12e23c4dfe
12 changed files with 65 additions and 20 deletions

2
.gitignore vendored
View file

@ -2,3 +2,5 @@ db.sqlite3
*.swp
*.pyc
__pycache__/
localsettings.py
migrations/

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# Paysafecard Dealer
## TODO
* Find a way to reliably purchase PSCs automatically and implement this in the buyer app

View file

@ -8,7 +8,7 @@ Bitte gib hier den sechsstelligen Code ein, den du per SMS erhalten hast:
<script>
function sendForm(){
$.ajax({
url: "/smsauth/",
url: "{{ request.path }}",
data: $('#tform').serialize(),
method: "POST",
success: function( result ) {

View file

@ -0,0 +1 @@
Zurzeit sind leider keine Karten verfügbar. Bitte versuche es später nochmal.

View file

@ -7,7 +7,7 @@
{% for item in items %}
<tr>
<td>{{ item.date }}</td>
<td>{{ item.description }}</td>
<td>{{ item.description }}{% if item.card %} <a rel="modal:open" href="{% url "resmsauth" item.id %}"><i style="color: blue;" class="fas fa-credit-card"></i></a>{% endif %}{% if item.attachment %} <a href="{{ item.attachment.url }}"><i style="color: chartreuse;" class="fas fa-file-download"></i></a>{% endif %}</td>
<td>{{ item.amount }} €</td>
</tr>
{% endfor %}

View file

@ -15,10 +15,12 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from frontend.views import IndexView, SMSAuthView, CardView
from frontend.views import IndexView, SMSAuthView, CardView, UnavailableView
urlpatterns = [
path('', IndexView.as_view(), name="index"),
path('smsauth/', SMSAuthView.as_view(), name="smsauth"),
path('card/<slug:uuid>/', CardView.as_view(), name="card")
path('smsauth/<int:id>/', SMSAuthView.as_view(), name="resmsauth"),
path('card/<slug:uuid>/', CardView.as_view(), name="card"),
path('unavailable/', UnavailableView.as_view(), name="unavailable")
]

View file

@ -19,14 +19,21 @@ class IndexView(LoginRequiredMixin, TemplateView):
class SMSAuthView(LoginRequiredMixin, FormView):
template_name = "frontend/form.html"
form_class = SMSAuthForm
additional_context = dict()
def get_context_data(self, **kwargs):
requestToken()
return super(SMSAuthView, self).get_context_data(**kwargs)
def form_valid(self, form):
Payment.objects.create(description="Paysafecard", amount=11) # pylint: disable=E1101
return redirect("/card/%s/" % makeCardURL(getCard()).uuid)
try:
card = Payment.objects.get(id=self.kwargs["id"]).card if self.kwargs.get("id") else getCard() # pylint: disable=E1101
return_url = "/card/%s/" % makeCardURL(card).uuid
except:
return redirect("unavailable")
if not card.delivered:
Payment.objects.create(description="Paysafecard", amount=11, card=card) # pylint: disable=E1101
return redirect(return_url)
class CardView(LoginRequiredMixin, DetailView):
template_name = "frontend/card.html"
@ -37,7 +44,11 @@ class CardView(LoginRequiredMixin, DetailView):
obj = super(CardView, self).get_object(queryset=queryset)
if timezone.now() - timedelta(seconds=300) > obj.created:
raise Http404()
obj.card.delivered = timezone.now()
obj.card.save()
if not obj.card.delivered:
obj.card.delivered = timezone.now()
obj.card.save()
sendStatus()
return obj
class UnavailableView(LoginRequiredMixin, TemplateView):
template_name = "frontend/unavailable.html"

View file

@ -1,5 +1,7 @@
from django.db import models
from buyer.models import Card
# Create your models here.
class Payment(models.Model):
@ -7,6 +9,8 @@ class Payment(models.Model):
amount = models.DecimalField("Payment amount", max_digits=15, decimal_places=2)
date = models.DateTimeField("Date of payment", auto_now_add=True)
repayment = models.DateTimeField("Date of repayment", default=None, null=True, blank=True)
card = models.ForeignKey(Card, models.SET_NULL, null=True, blank=True)
attachment = models.FileField("uploads", null=True, blank=True)
def __str__(self):
return self.description

12
localsettings.dist.py Normal file
View file

@ -0,0 +1,12 @@
SECRET_KEY = "longrandomstring"
DEBUG = False
ALLOWED_HOSTS = ["*"] # Rationale: The application should be running behind a reverse proxy anyway - let that handle which hosts are allowed
STATIC_ROOT = '/var/www/html/static/' # Directory where static files will be stored (to be served by web server at /static/)
AWS_ACCESS_KEY_ID = None
AWS_SECRET_ACCESS_KEY = None
AWS_STORAGE_BUCKET_NAME = None
AWS_S3_ENDPOINT_URL = None

View file

@ -1,5 +1,7 @@
selenium
bs4
twilio
django-bulk-admin
django
django-storages
boto3
git+https://kumig.it/kumisystems/pykumisms.git

View file

@ -2,8 +2,8 @@ from django.shortcuts import render
from django.utils import timezone
from datetime import timedelta
from smsauth.models import Token
from twilio.rest import Client
from dbsettings.views import getValue
from kumisms import KumiSMS
import random
def generateToken():
@ -23,8 +23,8 @@ def useToken(token):
def requestToken():
token = generateToken()
storeToken(token)
return sendSMS("Bitte verwende diesen Code, um deine Bestellung zu bestätigen: %s" % token, getValue("smsauth.recipient"))
return sendSMS("Bitte verwende diesen Code, um deine Anfrage zu bestätigen: %s" % token, getValue("smsauth.recipient"))
def sendSMS(text, recipient):
client = Client(getValue("smsauth.twilio.sid"), getValue("smsauth.twilio.token"))
return client.messages.create(body=text, from_=getValue("smsauth.twilio.number"), to=recipient)
gateway = KumiSMS(getValue("smsauth.kumisms.key"))
return gateway.send(recipient, text)

View file

@ -1,4 +1,5 @@
import os
import localsettings
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -8,12 +9,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0+-=7^-2@b46n&w)82y)d=i90c)4(%9dpieb0i!^tldzy(o&ct'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
SECRET_KEY = localsettings.SECRET_KEY
DEBUG = localsettings.DEBUG
ALLOWED_HOSTS = localsettings.ALLOWED_HOSTS
# Application definition
@ -110,8 +108,16 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
AWS_ACCESS_KEY_ID = localsettings.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY = localsettings.AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME = localsettings.AWS_STORAGE_BUCKET_NAME
AWS_S3_ENDPOINT_URL = localsettings.AWS_S3_ENDPOINT_URL
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/html/static/'
STATIC_ROOT = 'static/'
# Custom settings for Susioma project