walidacja

This commit is contained in:
Jędrzej Klepacki 2020-12-31 15:15:23 +01:00
parent 9405c0c6d2
commit 50190ef354
12 changed files with 76795 additions and 12 deletions

View File

@ -1,4 +1,5 @@
from django.contrib import admin
from .models import Product
from .models import Product, Places
admin.site.register(Product)
admin.site.register(Places)

View File

@ -0,0 +1,21 @@
# Generated by Django 3.1.4 on 2020-12-31 12:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_product_wolontatriat'),
]
operations = [
migrations.CreateModel(
name='Places',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('city', models.TextField(default='', max_length=40)),
('woj_city', models.TextField(default='', max_length=40)),
],
),
]

View File

@ -25,3 +25,7 @@ class Product(models.Model):
description = models.TextField(max_length=6000, blank=False, default="")
place = models.TextField(max_length=40, blank=False, default="")
keywords = models.TextField(max_length=6000, blank=False, default="")
class Places(models.Model):
city = models.TextField(max_length=40, blank=False, default="")
woj_city = models.TextField(max_length=40, blank=False, default="")

View File

@ -3,6 +3,8 @@
{% block content %}
<!DOCTYPE html>
<html lang="en" class="h-100">
<body class="h-100">
<!--================Categories Banner Area =================-->
@ -74,7 +76,13 @@
<div class="row h-100 justify-content-center align-items-center">
<div class="col-10 col-md-8 col-lg-6">
<label for="name">Miejscowość <span>*</span></label>
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="place">
<input list="browsers" name="browser" id="browser" class="form-control" aria-describedby="name">
<datalist id="browsers">
{% for place in place_list %}
<option value = "{{place.city}}, {{place.woj_city}}" >
{% endfor %}
</datalist>
</div>
</div>
</div>

View File

@ -132,7 +132,17 @@ body {font-family: Arial, Helvetica, sans-serif;}
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="col-10 col-md-8 col-lg-6">
<input type="checkbox" id="scales" name="scales" >
<label for="name">Potwierdź hasło: <span>*</span></label>
<input type="password" class="form-control" id="name" aria-describedby="name" placeholder="" name="pow_password">
</div>
</div>
</div>
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="col-10 col-md-8 col-lg-6">
<input type="hidden" id="scales" name="scales" value="No">
<input type="checkbox" id="scales" name="scales" value="Yes">
<label>Zapoznałem się z <a id="myBtn" style="color:blue">Regulaminem</a></label>
<div id="myModal" class="modal">

View File

@ -84,11 +84,18 @@
<div class="row h-100 justify-content-center align-items-center">
<div class="col-10 col-md-8 col-lg-6">
<label for="name">Miejscowość <span>*</span></label>
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="place" value={{ offer.place }}>
<input list="browsers" name="browser" id="browser" class="form-control" aria-describedby="name" value={{ offer.place }}>
<datalist id="browsers">
{% for place in place_list %}
<option value = "{{place.city}}, {{place.woj_city}}" >
{% endfor %}
</datalist>
</div>
</div>
</div>
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="col-10 col-md-8 col-lg-6">

View File

@ -7,7 +7,7 @@ from django.template import loader
from django.contrib.auth import get_user_model
from django.contrib import messages, auth
from .models import Product, TYPE_T, TYPE_O
from .models import Product, TYPE_T, TYPE_O, Places
from django.utils import timezone
from datetime import timedelta
@ -161,9 +161,10 @@ def filter(request):
return HttpResponse(template.render(context, request))
def add_offer(request):
place_list = Places.objects.all()
if request.user.is_authenticated:
if request.method == 'POST':
place_local = request.POST['place']
place_local = request.POST['browser']
type_local = request.POST['type']
script_local = request.POST['script']
title_local = request.POST['title']
@ -181,6 +182,17 @@ def add_offer(request):
else:
pic_local = "/images/basic.png"
offer_local = request.POST['offer']
if title_local == "":
messages.error(request,'Musisz podać tytuł!')
return redirect('add_offer')
if script_local == "":
messages.error(request,'Musisz podać opis!')
return redirect('add_offer')
if place_local == "":
messages.error(request,'Musisz podać miejscowość!')
return redirect('add_offer')
product = Product(
picture = pic_local,
Wolontatriat = wol,
@ -196,7 +208,10 @@ def add_offer(request):
product.save()
messages.success(request, 'Ogłoszenie dodane!')
return redirect(my_offer)
return render(request , 'homepage/add_offer.html')
context = {
'place_list': place_list,
}
return render(request , 'homepage/add_offer.html', context)
else:
return redirect(login)
@ -212,13 +227,15 @@ def edit_offer(request, offer_id):
instance = Product.objects.get(id=offer_id)
types = TYPE_T
types_o = TYPE_O
place_list = Places.objects.all()
context = {
'offer': instance,
'place_list': place_list,
'types': types,
'types_o': types_o,
}
if request.method == 'POST':
place_local = request.POST['place']
place_local = request.POST['browser']
type_local = request.POST['type']
script_local = request.POST['script']
title_local = request.POST['title']
@ -229,6 +246,16 @@ def edit_offer(request, offer_id):
else:
wol = True
if title_local == "":
messages.error(request,'Musisz podać tytuł!')
return redirect('add_offer')
if script_local == "":
messages.error(request,'Musisz podać opis!')
return redirect('add_offer')
if place_local == "":
messages.error(request,'Musisz podać miejscowość!')
return redirect('add_offer')
if request.FILES:
pic_local = request.FILES['file']
instance.picture = pic_local
@ -253,6 +280,13 @@ def create_user(request):
User = get_user_model()
email = request.POST['email']
password = request.POST['password']
pow_password = request.POST['pow_password']
scales = request.POST['scales']
#walidacja
if scales == "No":
messages.error(request,'Musisz zaakceptować regulamin!')
return redirect('create_user')
if email == "":
messages.error(request,'Pole email jest puste!')
return redirect('create_user')
@ -261,13 +295,43 @@ def create_user(request):
messages.error(request,'Wprowadzony email jest niepoprawny!')
return redirect('create_user')
if User.objects.filter(email=email).exists():
messages.error(request,'Ten adres e-mail jest już używany')
return redirect('create_user')
if password == "":
messages.error(request,'Pole hasło jest puste!')
return redirect('create_user')
if User.objects.filter(email=email).exists():
messages.error(request,'Ten adres e-mail jest już używany')
if password != pow_password:
messages.error(request,'Podane hasła są różne')
return redirect('create_user')
if password == email:
messages.error(request,'Podane hasła i email muszą byc różne')
return redirect('create_user')
dlugosc = 0
znak = 0
duza = 0
mala = 0
cyfra = 0
for i in password:
if i in "1234567890":
cyfra = 1
elif i in "QWERTYUIOPASDFGHJKLZXCVBNM":
duza = 1
elif i in "qwertyuiopasdfghjklzxcvbnm":
mala = 1
elif i in "!@#$%&*(){}[]<>?":
znak = 1
if len(password) >= 8:
dlugosc = 1
if dlugosc+znak+mala+duza+cyfra != 5:
messages.error(request,'Podane hasło jest nieprawidłowe. Hasło musi zawierać conajmniej: 1 cyfre, 1 duza litere, 1 mala litere, 1 znak specjalny z zakresu !@#$%&*(){}[]<>?, oraz składać sie conajmniej z 8 symboli')
return redirect('create_user')
else:
user = User(
username = email,

76668
SocialHelper/placess.csv.csv Normal file

File diff suppressed because it is too large Load Diff