autoryzacja logowania
This commit is contained in:
parent
35b36b3300
commit
d04a86f750
Binary file not shown.
@ -4,7 +4,11 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
|
<style>
|
||||||
|
.tabcontent {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<!--================Categories Banner Area =================-->
|
<!--================Categories Banner Area =================-->
|
||||||
<section class="solid_banner_area">
|
<section class="solid_banner_area">
|
||||||
@ -74,9 +78,10 @@
|
|||||||
<div class="row justify-content-md-center">
|
<div class="row justify-content-md-center">
|
||||||
{% if user_get_id == offer.user_iden.id %}
|
{% if user_get_id == offer.user_iden.id %}
|
||||||
<div class="col-lg-4 col-md-6">
|
<div class="col-lg-4 col-md-6">
|
||||||
<div class="tab">
|
<div class="tab" style="text-align:right;">
|
||||||
|
|
||||||
{% for user in email_list %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -169,8 +169,8 @@ def filter(request):
|
|||||||
return HttpResponse(template.render(context, request))
|
return HttpResponse(template.render(context, request))
|
||||||
|
|
||||||
def add_offer(request):
|
def add_offer(request):
|
||||||
place_list = Places.objects.all()
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
place_list = Places.objects.all()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
place_local = request.POST['browser']
|
place_local = request.POST['browser']
|
||||||
type_local = request.POST['type']
|
type_local = request.POST['type']
|
||||||
@ -224,64 +224,78 @@ def add_offer(request):
|
|||||||
return redirect(login)
|
return redirect(login)
|
||||||
|
|
||||||
def delete_offer(request, offer_id):
|
def delete_offer(request, offer_id):
|
||||||
instance = Product.objects.get(id=offer_id)
|
if request.user.is_authenticated:
|
||||||
instance.active = False
|
if Product.objects.filter(user_iden=request.user , id = offer_id).exists():
|
||||||
instance.save()
|
instance = Product.objects.get(id=offer_id)
|
||||||
messages.success(request, 'Ogłoszenie usunięte!')
|
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):
|
def edit_offer(request, offer_id):
|
||||||
instance = Product.objects.get(id=offer_id)
|
if request.user.is_authenticated:
|
||||||
types = TYPE_T
|
if Product.objects.filter(user_iden=request.user , id = offer_id).exists():
|
||||||
types_o = TYPE_O
|
instance = Product.objects.get(id=offer_id)
|
||||||
place_list = Places.objects.all()
|
types = TYPE_T
|
||||||
context = {
|
types_o = TYPE_O
|
||||||
'offer': instance,
|
place_list = Places.objects.all()
|
||||||
'place_list': place_list,
|
context = {
|
||||||
'types': types,
|
'offer': instance,
|
||||||
'types_o': types_o,
|
'place_list': place_list,
|
||||||
}
|
'types': types,
|
||||||
if request.method == 'POST':
|
'types_o': types_o,
|
||||||
place_local = request.POST['browser']
|
}
|
||||||
type_local = request.POST['type']
|
if request.method == 'POST':
|
||||||
script_local = request.POST['script']
|
place_local = request.POST['browser']
|
||||||
title_local = request.POST['title']
|
type_local = request.POST['type']
|
||||||
|
script_local = request.POST['script']
|
||||||
|
title_local = request.POST['title']
|
||||||
|
|
||||||
wol_local = request.POST['wol']
|
wol_local = request.POST['wol']
|
||||||
if wol_local == "1":
|
if wol_local == "1":
|
||||||
wol = False
|
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:
|
else:
|
||||||
wol = True
|
messages.error(request, 'Nie masz uprawnień!')
|
||||||
|
return redirect(index)
|
||||||
if title_local == "":
|
else:
|
||||||
messages.error(request,'Musisz podać tytuł!')
|
return redirect(login)
|
||||||
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)
|
|
||||||
|
|
||||||
def create_user(request):
|
def create_user(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -355,64 +369,70 @@ def create_user(request):
|
|||||||
return render(request , 'homepage/create_user.html')
|
return render(request , 'homepage/create_user.html')
|
||||||
|
|
||||||
def delete_user(request):
|
def delete_user(request):
|
||||||
User = get_user_model()
|
if request.user.is_authenticated:
|
||||||
instant = User.objects.filter(id=request.user.id).first()
|
User = get_user_model()
|
||||||
instant.is_active = False
|
instant = User.objects.filter(id=request.user.id).first()
|
||||||
instant.email = str(instant.id)
|
instant.is_active = False
|
||||||
instant.username = str(instant.id)
|
instant.email = str(instant.id)
|
||||||
instant_offer = Product.objects.filter(user_iden = instant)
|
instant.username = str(instant.id)
|
||||||
for offer in instant_offer:
|
instant_offer = Product.objects.filter(user_iden = instant)
|
||||||
offer.active = False
|
for offer in instant_offer:
|
||||||
offer.save()
|
offer.active = False
|
||||||
instant.save()
|
offer.save()
|
||||||
|
instant.save()
|
||||||
|
|
||||||
messages.success(request,'Konto skasowane!')
|
messages.success(request,'Konto skasowane!')
|
||||||
return redirect(index)
|
return redirect(index)
|
||||||
|
else:
|
||||||
|
return redirect(login)
|
||||||
|
|
||||||
def edit_user(request):
|
def edit_user(request):
|
||||||
User = get_user_model()
|
if request.user.is_authenticated:
|
||||||
instant = User.objects.filter(id=request.user.id).first()
|
User = get_user_model()
|
||||||
if request.method == 'POST':
|
instant = User.objects.filter(id=request.user.id).first()
|
||||||
|
if request.method == 'POST':
|
||||||
|
|
||||||
oldpassword = request.POST['oldpassword']
|
oldpassword = request.POST['oldpassword']
|
||||||
newpassword1 = request.POST['newpassword1']
|
newpassword1 = request.POST['newpassword1']
|
||||||
newpassword2 = request.POST['newpassword2']
|
newpassword2 = request.POST['newpassword2']
|
||||||
user = authenticate(request, username=instant.username, password=oldpassword, is_active=True)
|
user = authenticate(request, username=instant.username, password=oldpassword, is_active=True)
|
||||||
if user is None:
|
if user is None:
|
||||||
messages.error(request,'Podałeś złe hasło')
|
messages.error(request,'Podałeś złe hasło')
|
||||||
return redirect('edit_user')
|
return redirect('edit_user')
|
||||||
|
|
||||||
dlugosc = 0
|
dlugosc = 0
|
||||||
znak = 0
|
znak = 0
|
||||||
duza = 0
|
duza = 0
|
||||||
mala = 0
|
mala = 0
|
||||||
cyfra = 0
|
cyfra = 0
|
||||||
for i in newpassword1:
|
for i in newpassword1:
|
||||||
if i in "1234567890":
|
if i in "1234567890":
|
||||||
cyfra = 1
|
cyfra = 1
|
||||||
elif i in "QWERTYUIOPASDFGHJKLZXCVBNM":
|
elif i in "QWERTYUIOPASDFGHJKLZXCVBNM":
|
||||||
duza = 1
|
duza = 1
|
||||||
elif i in "qwertyuiopasdfghjklzxcvbnm":
|
elif i in "qwertyuiopasdfghjklzxcvbnm":
|
||||||
mala = 1
|
mala = 1
|
||||||
elif i in "!@#$%&*(){}[]<>?":
|
elif i in "!@#$%&*(){}[]<>?":
|
||||||
znak = 1
|
znak = 1
|
||||||
if len(newpassword1) >= 8:
|
if len(newpassword1) >= 8:
|
||||||
dlugosc = 1
|
dlugosc = 1
|
||||||
|
|
||||||
if dlugosc+znak+mala+duza+cyfra != 5:
|
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')
|
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')
|
return redirect('edit_user')
|
||||||
|
|
||||||
if newpassword1 != newpassword2:
|
if newpassword1 != newpassword2:
|
||||||
messages.error(request,'Podane nowe hasła są różne')
|
messages.error(request,'Podane nowe hasła są różne')
|
||||||
return redirect('edit_user')
|
return redirect('edit_user')
|
||||||
|
|
||||||
instant.set_password(newpassword1)
|
instant.set_password(newpassword1)
|
||||||
instant.save()
|
instant.save()
|
||||||
messages.success(request,'Hasło zmienione, nastąpiło wylogowanie!')
|
messages.success(request,'Hasło zmienione, nastąpiło wylogowanie!')
|
||||||
return redirect('my_offer')
|
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):
|
def login(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -497,7 +517,6 @@ def add_comment(request, user_name):
|
|||||||
else:
|
else:
|
||||||
return redirect(login)
|
return redirect(login)
|
||||||
|
|
||||||
|
|
||||||
def offer(request, offer_id):
|
def offer(request, offer_id):
|
||||||
user_get_id = request.user.id
|
user_get_id = request.user.id
|
||||||
offer = Product.objects.filter(id = offer_id, active = True).first()
|
offer = Product.objects.filter(id = offer_id, active = True).first()
|
||||||
@ -564,37 +583,40 @@ def send_message(request):
|
|||||||
return redirect(login)
|
return redirect(login)
|
||||||
|
|
||||||
def chating(request, offer_id, au_id, ad_id):
|
def chating(request, offer_id, au_id, ad_id):
|
||||||
scd_user_get_id = ad_id
|
if request.user.is_authenticated:
|
||||||
User = get_user_model()
|
scd_user_get_id = ad_id
|
||||||
user_prof = User.objects.filter(id=au_id).first()
|
User = get_user_model()
|
||||||
mess = 0
|
user_prof = User.objects.filter(id=au_id).first()
|
||||||
user_get_id = request.user.id
|
mess = 0
|
||||||
if chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id ).exists():
|
user_get_id = request.user.id
|
||||||
chat_fst = chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id)
|
if chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id ).exists():
|
||||||
else:
|
chat_fst = chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id)
|
||||||
chat_fst = chat.objects.none()
|
else:
|
||||||
mess = mess + 1
|
chat_fst = chat.objects.none()
|
||||||
user_prof_2 = User.objects.filter(id=ad_id).first()
|
mess = mess + 1
|
||||||
if chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id).exists():
|
user_prof_2 = User.objects.filter(id=ad_id).first()
|
||||||
chat_scd = chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id)
|
if chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id).exists():
|
||||||
else:
|
chat_scd = chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id)
|
||||||
chat_scd = chat.objects.none()
|
else:
|
||||||
mess = mess + 1
|
chat_scd = chat.objects.none()
|
||||||
|
mess = mess + 1
|
||||||
|
|
||||||
if mess == 2:
|
if mess == 2:
|
||||||
mess = chat.objects.none()
|
mess = chat.objects.none()
|
||||||
user_list = chat.objects.none()
|
user_list = chat.objects.none()
|
||||||
email_list = chat.objects.none()
|
email_list = chat.objects.none()
|
||||||
else:
|
else:
|
||||||
mess = chat_fst.union(chat_scd).order_by('pub_date')
|
mess = chat_fst.union(chat_scd).order_by('pub_date')
|
||||||
|
|
||||||
last_date = 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()
|
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 ={
|
context ={
|
||||||
'mess': mess,
|
'mess': mess,
|
||||||
'user_get_id': user_get_id,
|
'user_get_id': user_get_id,
|
||||||
'scd_user_get_id': scd_user_get_id,
|
'scd_user_get_id': scd_user_get_id,
|
||||||
'last_date': last_date
|
'last_date': last_date
|
||||||
}
|
}
|
||||||
template = loader.get_template('homepage/chating.html')
|
template = loader.get_template('homepage/chating.html')
|
||||||
return HttpResponse(template.render(context, request))
|
return HttpResponse(template.render(context, request))
|
||||||
|
else:
|
||||||
|
return redirect(login)
|
||||||
|
Loading…
Reference in New Issue
Block a user