autoryzacja logowania

This commit is contained in:
Jędrzej Klepacki 2021-01-15 11:22:54 +01:00
parent 35b36b3300
commit d04a86f750
3 changed files with 166 additions and 139 deletions

View File

@ -4,7 +4,11 @@
<!DOCTYPE html>
<html lang="en">
<body>
<style>
.tabcontent {
display: none;
}
</style>
<!--================Categories Banner Area =================-->
<section class="solid_banner_area">
@ -74,9 +78,10 @@
<div class="row justify-content-md-center">
{% if user_get_id == offer.user_iden.id %}
<div class="col-lg-4 col-md-6">
<div class="tab">
<div class="tab" style="text-align:right;">
{% for user in email_list %}
<button onclick="openCity(event, '{{ user.id }}')" width="200" >{{ user.email }}</button><p></p>
<button onclick="openCity(event, '{{ user.id }}')" checked >{{ user.email }}</button><p></p>
{% endfor %}
</div>
</div>

View File

@ -169,8 +169,8 @@ def filter(request):
return HttpResponse(template.render(context, request))
def add_offer(request):
place_list = Places.objects.all()
if request.user.is_authenticated:
place_list = Places.objects.all()
if request.method == 'POST':
place_local = request.POST['browser']
type_local = request.POST['type']
@ -224,64 +224,78 @@ def add_offer(request):
return redirect(login)
def delete_offer(request, offer_id):
instance = Product.objects.get(id=offer_id)
instance.active = False
instance.save()
messages.success(request, 'Ogłoszenie usunięte!')
if request.user.is_authenticated:
if Product.objects.filter(user_iden=request.user , id = offer_id).exists():
instance = Product.objects.get(id=offer_id)
instance.active = False
instance.save()
messages.success(request, 'Ogłoszenie usunięte!')
return redirect(my_offer)
else:
messages.error(request, 'Nie masz uprawnień!')
return redirect(index)
else:
return redirect(login)
return redirect(my_offer)
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['browser']
type_local = request.POST['type']
script_local = request.POST['script']
title_local = request.POST['title']
if request.user.is_authenticated:
if Product.objects.filter(user_iden=request.user , id = offer_id).exists():
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['browser']
type_local = request.POST['type']
script_local = request.POST['script']
title_local = request.POST['title']
wol_local = request.POST['wol']
if wol_local == "1":
wol = False
wol_local = request.POST['wol']
if wol_local == "1":
wol = False
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
offer_local = request.POST['offer']
instance.Wolontatriat = wol
instance.type = int(type_local)
instance.offer = int(offer_local)
instance.title = title_local
instance.description = script_local
instance.place= place_local
instance.keywords = ""
instance.save()
messages.success(request, 'Ogłoszenie edytowane!')
return redirect(my_offer)
return render(request , 'homepage/edycja_ogloszenia.html', context)
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
offer_local = request.POST['offer']
instance.Wolontatriat = wol
instance.type = int(type_local)
instance.offer = int(offer_local)
instance.title = title_local
instance.description = script_local
instance.place= place_local
instance.keywords = ""
instance.save()
messages.success(request, 'Ogłoszenie edytowane!')
return redirect(my_offer)
return render(request , 'homepage/edycja_ogloszenia.html', context)
messages.error(request, 'Nie masz uprawnień!')
return redirect(index)
else:
return redirect(login)
def create_user(request):
if request.method == 'POST':
@ -355,64 +369,70 @@ def create_user(request):
return render(request , 'homepage/create_user.html')
def delete_user(request):
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
instant.is_active = False
instant.email = str(instant.id)
instant.username = str(instant.id)
instant_offer = Product.objects.filter(user_iden = instant)
for offer in instant_offer:
offer.active = False
offer.save()
instant.save()
if request.user.is_authenticated:
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
instant.is_active = False
instant.email = str(instant.id)
instant.username = str(instant.id)
instant_offer = Product.objects.filter(user_iden = instant)
for offer in instant_offer:
offer.active = False
offer.save()
instant.save()
messages.success(request,'Konto skasowane!')
return redirect(index)
messages.success(request,'Konto skasowane!')
return redirect(index)
else:
return redirect(login)
def edit_user(request):
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
if request.method == 'POST':
if request.user.is_authenticated:
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
if request.method == 'POST':
oldpassword = request.POST['oldpassword']
newpassword1 = request.POST['newpassword1']
newpassword2 = request.POST['newpassword2']
user = authenticate(request, username=instant.username, password=oldpassword, is_active=True)
if user is None:
messages.error(request,'Podałeś złe hasło')
return redirect('edit_user')
oldpassword = request.POST['oldpassword']
newpassword1 = request.POST['newpassword1']
newpassword2 = request.POST['newpassword2']
user = authenticate(request, username=instant.username, password=oldpassword, is_active=True)
if user is None:
messages.error(request,'Podałeś złe hasło')
return redirect('edit_user')
dlugosc = 0
znak = 0
duza = 0
mala = 0
cyfra = 0
for i in newpassword1:
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(newpassword1) >= 8:
dlugosc = 1
dlugosc = 0
znak = 0
duza = 0
mala = 0
cyfra = 0
for i in newpassword1:
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(newpassword1) >= 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('edit_user')
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('edit_user')
if newpassword1 != newpassword2:
messages.error(request,'Podane nowe hasła są różne')
return redirect('edit_user')
if newpassword1 != newpassword2:
messages.error(request,'Podane nowe hasła są różne')
return redirect('edit_user')
instant.set_password(newpassword1)
instant.save()
messages.success(request,'Hasło zmienione, nastąpiło wylogowanie!')
return redirect('my_offer')
instant.set_password(newpassword1)
instant.save()
messages.success(request,'Hasło zmienione, nastąpiło wylogowanie!')
return redirect('my_offer')
return render(request , 'homepage/edit_user.html')
return render(request , 'homepage/edit_user.html')
else:
return redirect(login)
def login(request):
if request.method == 'POST':
@ -497,7 +517,6 @@ def add_comment(request, user_name):
else:
return redirect(login)
def offer(request, offer_id):
user_get_id = request.user.id
offer = Product.objects.filter(id = offer_id, active = True).first()
@ -564,37 +583,40 @@ def send_message(request):
return redirect(login)
def chating(request, offer_id, au_id, ad_id):
scd_user_get_id = ad_id
User = get_user_model()
user_prof = User.objects.filter(id=au_id).first()
mess = 0
user_get_id = request.user.id
if chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id ).exists():
chat_fst = chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id)
else:
chat_fst = chat.objects.none()
mess = mess + 1
user_prof_2 = User.objects.filter(id=ad_id).first()
if chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id).exists():
chat_scd = chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id)
else:
chat_scd = chat.objects.none()
mess = mess + 1
if request.user.is_authenticated:
scd_user_get_id = ad_id
User = get_user_model()
user_prof = User.objects.filter(id=au_id).first()
mess = 0
user_get_id = request.user.id
if chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id ).exists():
chat_fst = chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id)
else:
chat_fst = chat.objects.none()
mess = mess + 1
user_prof_2 = User.objects.filter(id=ad_id).first()
if chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id).exists():
chat_scd = chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id)
else:
chat_scd = chat.objects.none()
mess = mess + 1
if mess == 2:
mess = chat.objects.none()
user_list = chat.objects.none()
email_list = chat.objects.none()
else:
mess = chat_fst.union(chat_scd).order_by('pub_date')
if mess == 2:
mess = chat.objects.none()
user_list = chat.objects.none()
email_list = chat.objects.none()
else:
mess = chat_fst.union(chat_scd).order_by('pub_date')
last_date = chat_fst.union(chat_scd).order_by('pub_date')
last_date = chat.objects.filter(Q(product_id = offer_id), Q(author_id=user_prof.id) | Q(author_id=user_prof_2.id), Q(sec_user_id=ad_id) | Q(sec_user_id=au_id)).order_by('pub_date').last()
context ={
'mess': mess,
'user_get_id': user_get_id,
'scd_user_get_id': scd_user_get_id,
'last_date': last_date
}
template = loader.get_template('homepage/chating.html')
return HttpResponse(template.render(context, request))
last_date = chat_fst.union(chat_scd).order_by('pub_date')
last_date = chat.objects.filter(Q(product_id = offer_id), Q(author_id=user_prof.id) | Q(author_id=user_prof_2.id), Q(sec_user_id=ad_id) | Q(sec_user_id=au_id)).order_by('pub_date').last()
context ={
'mess': mess,
'user_get_id': user_get_id,
'scd_user_get_id': scd_user_get_id,
'last_date': last_date
}
template = loader.get_template('homepage/chating.html')
return HttpResponse(template.render(context, request))
else:
return redirect(login)