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,14 +224,23 @@ def add_offer(request):
return redirect(login)
def delete_offer(request, offer_id):
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)
def edit_offer(request, offer_id):
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
@ -282,6 +291,11 @@ def edit_offer(request, offer_id):
messages.success(request, 'Ogłoszenie edytowane!')
return redirect(my_offer)
return render(request , 'homepage/edycja_ogloszenia.html', context)
else:
messages.error(request, 'Nie masz uprawnień!')
return redirect(index)
else:
return redirect(login)
def create_user(request):
if request.method == 'POST':
@ -355,6 +369,7 @@ def create_user(request):
return render(request , 'homepage/create_user.html')
def delete_user(request):
if request.user.is_authenticated:
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
instant.is_active = False
@ -368,8 +383,11 @@ def delete_user(request):
messages.success(request,'Konto skasowane!')
return redirect(index)
else:
return redirect(login)
def edit_user(request):
if request.user.is_authenticated:
User = get_user_model()
instant = User.objects.filter(id=request.user.id).first()
if request.method == 'POST':
@ -413,6 +431,8 @@ def edit_user(request):
return redirect('my_offer')
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,6 +583,7 @@ def send_message(request):
return redirect(login)
def chating(request, offer_id, au_id, ad_id):
if request.user.is_authenticated:
scd_user_get_id = ad_id
User = get_user_model()
user_prof = User.objects.filter(id=au_id).first()
@ -598,3 +618,5 @@ def chating(request, offer_id, au_id, ad_id):
}
template = loader.get_template('homepage/chating.html')
return HttpResponse(template.render(context, request))
else:
return redirect(login)