Make stuff a little prettier
This commit is contained in:
parent
3076ab1ad4
commit
12e23c4dfe
12 changed files with 65 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@ db.sqlite3
|
||||||
*.swp
|
*.swp
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
localsettings.py
|
||||||
|
migrations/
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Paysafecard Dealer
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
* Find a way to reliably purchase PSCs automatically and implement this in the buyer app
|
|
@ -8,7 +8,7 @@ Bitte gib hier den sechsstelligen Code ein, den du per SMS erhalten hast:
|
||||||
<script>
|
<script>
|
||||||
function sendForm(){
|
function sendForm(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/smsauth/",
|
url: "{{ request.path }}",
|
||||||
data: $('#tform').serialize(),
|
data: $('#tform').serialize(),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
success: function( result ) {
|
success: function( result ) {
|
||||||
|
|
1
frontend/templates/frontend/unavailable.html
Normal file
1
frontend/templates/frontend/unavailable.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Zurzeit sind leider keine Karten verfügbar. Bitte versuche es später nochmal.
|
|
@ -7,7 +7,7 @@
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ item.date }}</td>
|
<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>
|
<td>{{ item.amount }} €</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -15,10 +15,12 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from frontend.views import IndexView, SMSAuthView, CardView
|
from frontend.views import IndexView, SMSAuthView, CardView, UnavailableView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', IndexView.as_view(), name="index"),
|
path('', IndexView.as_view(), name="index"),
|
||||||
path('smsauth/', SMSAuthView.as_view(), name="smsauth"),
|
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")
|
||||||
]
|
]
|
|
@ -19,14 +19,21 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
||||||
class SMSAuthView(LoginRequiredMixin, FormView):
|
class SMSAuthView(LoginRequiredMixin, FormView):
|
||||||
template_name = "frontend/form.html"
|
template_name = "frontend/form.html"
|
||||||
form_class = SMSAuthForm
|
form_class = SMSAuthForm
|
||||||
|
additional_context = dict()
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
requestToken()
|
requestToken()
|
||||||
return super(SMSAuthView, self).get_context_data(**kwargs)
|
return super(SMSAuthView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
Payment.objects.create(description="Paysafecard", amount=11) # pylint: disable=E1101
|
try:
|
||||||
return redirect("/card/%s/" % makeCardURL(getCard()).uuid)
|
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):
|
class CardView(LoginRequiredMixin, DetailView):
|
||||||
template_name = "frontend/card.html"
|
template_name = "frontend/card.html"
|
||||||
|
@ -37,7 +44,11 @@ class CardView(LoginRequiredMixin, DetailView):
|
||||||
obj = super(CardView, self).get_object(queryset=queryset)
|
obj = super(CardView, self).get_object(queryset=queryset)
|
||||||
if timezone.now() - timedelta(seconds=300) > obj.created:
|
if timezone.now() - timedelta(seconds=300) > obj.created:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
if not obj.card.delivered:
|
||||||
obj.card.delivered = timezone.now()
|
obj.card.delivered = timezone.now()
|
||||||
obj.card.save()
|
obj.card.save()
|
||||||
sendStatus()
|
sendStatus()
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
class UnavailableView(LoginRequiredMixin, TemplateView):
|
||||||
|
template_name = "frontend/unavailable.html"
|
|
@ -1,5 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from buyer.models import Card
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Payment(models.Model):
|
class Payment(models.Model):
|
||||||
|
@ -7,6 +9,8 @@ class Payment(models.Model):
|
||||||
amount = models.DecimalField("Payment amount", max_digits=15, decimal_places=2)
|
amount = models.DecimalField("Payment amount", max_digits=15, decimal_places=2)
|
||||||
date = models.DateTimeField("Date of payment", auto_now_add=True)
|
date = models.DateTimeField("Date of payment", auto_now_add=True)
|
||||||
repayment = models.DateTimeField("Date of repayment", default=None, null=True, blank=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):
|
def __str__(self):
|
||||||
return self.description
|
return self.description
|
12
localsettings.dist.py
Normal file
12
localsettings.dist.py
Normal 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
|
|
@ -1,5 +1,7 @@
|
||||||
selenium
|
selenium
|
||||||
bs4
|
bs4
|
||||||
twilio
|
|
||||||
django-bulk-admin
|
django-bulk-admin
|
||||||
django
|
django
|
||||||
|
django-storages
|
||||||
|
boto3
|
||||||
|
git+https://kumig.it/kumisystems/pykumisms.git
|
|
@ -2,8 +2,8 @@ from django.shortcuts import render
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from smsauth.models import Token
|
from smsauth.models import Token
|
||||||
from twilio.rest import Client
|
|
||||||
from dbsettings.views import getValue
|
from dbsettings.views import getValue
|
||||||
|
from kumisms import KumiSMS
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def generateToken():
|
def generateToken():
|
||||||
|
@ -23,8 +23,8 @@ def useToken(token):
|
||||||
def requestToken():
|
def requestToken():
|
||||||
token = generateToken()
|
token = generateToken()
|
||||||
storeToken(token)
|
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):
|
def sendSMS(text, recipient):
|
||||||
client = Client(getValue("smsauth.twilio.sid"), getValue("smsauth.twilio.token"))
|
gateway = KumiSMS(getValue("smsauth.kumisms.key"))
|
||||||
return client.messages.create(body=text, from_=getValue("smsauth.twilio.number"), to=recipient)
|
return gateway.send(recipient, text)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import localsettings
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
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/
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# 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'
|
SECRET_KEY = localsettings.SECRET_KEY
|
||||||
|
DEBUG = localsettings.DEBUG
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
ALLOWED_HOSTS = localsettings.ALLOWED_HOSTS
|
||||||
DEBUG = True
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -110,8 +108,16 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
# 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_URL = '/static/'
|
||||||
STATIC_ROOT = '/var/www/html/static/'
|
STATIC_ROOT = 'static/'
|
||||||
|
|
||||||
# Custom settings for Susioma project
|
# Custom settings for Susioma project
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue