Compare commits

..

10 Commits

Author SHA1 Message Date
Martin Quarda
e411e71b89 build page 2024-10-24 11:18:03 +02:00
Martin Quarda
d7411d90c4 test dockerfile 2024-10-24 10:57:10 +02:00
Martin Quarda
abdb62fd55 fixes 2024-10-18 16:25:56 +02:00
Martin Quarda
7c7f554fd0 fix 2024-10-18 08:53:44 +02:00
Martin Quarda
5e6baf64c3 fixes 2024-10-17 16:07:03 +02:00
Martin Quarda
4f98c97880 fix 2024-10-17 09:12:50 +02:00
Martin Quarda
b5c8c005c6 small fix 2024-10-17 09:08:55 +02:00
Martin Quarda
30b629235f small fix 2024-10-17 09:05:47 +02:00
Martin Quarda
505528c595 small fix 2024-10-17 08:59:29 +02:00
Martin Quarda
c71934ca98 new forgotten password mail 2024-10-17 08:53:24 +02:00
6 changed files with 39 additions and 9 deletions

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM greyltc/archlinux-aur:yay
WORKDIR /alkator
COPY . .
run pacman -Syu python python-weasyprint python-dateutil python-django npm --noconfirm
RUN sudo -u ab -D~ bash -c 'yay -Syu --removemake --needed --noprogressbar --noconfirm python-daphne'
RUN cd frontent && npm install && npm run build && rm -rf node_modules && cd ..
RUN python manage.py collectstatic
EXPOSE 8002
CMD ["/usr/bin/daphne", "alkator.asgi:application", "-p", "8002"]

View File

@ -32,6 +32,7 @@ CSRF_TRUSTED_ORIGINS = ['https://alkator.cz', 'https://beta.alkator.cz']
# Application definition
INSTALLED_APPS = [
'daphne',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -70,6 +71,7 @@ TEMPLATES = [
]
WSGI_APPLICATION = 'alkator.wsgi.application'
ASGI_APPLICATION = 'alkator.asgi.application'
SESSION_COOKIE_SECURE = True

View File

@ -16,6 +16,7 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from alkatorapi.views import (
register_user, register_racer,
login, logout,
@ -51,4 +52,4 @@ urlpatterns = [
path('api/cart/select_delivery', select_delivery),
path('api/cart/delivery', delivery),
path('api/forgotten_password', forgotten_password),
]
] + static('/', document_root='frontend/build')

View File

@ -10,7 +10,7 @@ class RacerAdmin(admin.ModelAdmin):
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ("name", "description", "price", "quantity")
list_display = ("name", "description", "price", "hidden", "quantity")
@admin.register(Invoice)

View File

@ -85,24 +85,43 @@ def forgotten_password(request):
user = DjangoUser.objects.get(username=request.POST['email'])
except DjangoUser.DoesNotExist:
return HttpResponse('{"reason":"Účet nenalezen!"}', status=404, content_type='application/json')
if user.profile.forgotten_password_code != request.POST['code']:
if user.profile.forgotten_password_code != request.POST['code'].strip():
return HttpResponse('{"reason":"Špatný kód!"}', status=400, content_type='application/json')
user.set_password(request.POST['password1'])
user.save()
user.profile.forgotten_password_code = None
user.profile.save()
auth_login(request, user)
return HttpResponse('{"success":"Úspěšně změněné heslo uživatele ' + user.email + '!", "redirect":"/#"}', content_type='application/json')
@csrf_exempt
def login(request):
if "forgotten_password" in request.POST:
email = request.POST["email"]
try:
user = DjangoUser.objects.get(username=email)
except DjangoUser.DoesNotExist:
return HttpResponse('{"reason":"Nezadané jméno nebo uživatel neexistuje!"}', status=404, content_type='application/json')
code = secrets.token_urlsafe(10)
user.profile.forgotten_password_code = code
user.profile.save()
mail = EmailMessage("zapomenuté heslo v Alkátor Race", f"""{code} https://alkator.cz/#forgotten_password""", "info@alkator.cz", [request.POST["email"]])
mail.send()
mail = EmailMessage("zapomenuté heslo v Alkátor Race", f"""Zdravím tě Alkátore,
kód pro změnu hesla: {code}
Změna hesla probíhá na stránce: https://alkator.cz/#forgotten_password
Na tento email není třeba odpovídat, protože je generován automaticky. V případě potřeby pište na info@alkator.cz .
ALKÁTOR TEAM
email: info@alkator.cz
tel: + 420 728 018 088
web: https://alkator.cz""", "info@alkator.cz", [email])
if mail.send():
return HttpResponse('{"success":"Úspěšně poslán kód pro obnovení hesla uživatele '+ user.email + '", "redirect":"/#forgotten_password"}', content_type='application/json')
else:
return HttpResponse('{"reason":"Nepovedlo se odelat email"}', status=400, content_type='application/json')
else:
try:
user = authenticate(request, username=request.POST['email'], password=request.POST['password'])
@ -117,7 +136,6 @@ def login(request):
@csrf_exempt
def logout(request):
auth_logout(request)
return redirect("/#")

View File

@ -515,7 +515,7 @@ class Main extends Component {
<label for="password2" class="form-label">Nové heslo znova:</label>
<input type="password" class="form-control" name="password2"/>
</div>
<button type="submit" class="btn btn-primary">Přihlásit</button>
<button type="submit" class="btn btn-primary">Obnovit heslo a přihlásit</button>
</form>
</div>
}