rejestracja

This commit is contained in:
Jędrzej Klepacki 2020-12-20 18:32:25 +01:00
parent f90a09688a
commit bcf438dbc0
19 changed files with 416 additions and 60 deletions

View File

@ -1,7 +1,9 @@
# Generated by Django 2.1.5 on 2020-12-10 20:03 # Generated by Django 3.1.4 on 2020-12-20 16:51
import datetime import datetime
from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -9,6 +11,7 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
@ -19,13 +22,13 @@ class Migration(migrations.Migration):
('active', models.BooleanField(default=True)), ('active', models.BooleanField(default=True)),
('picture', models.ImageField(blank=True, null=True, upload_to='images/')), ('picture', models.ImageField(blank=True, null=True, upload_to='images/')),
('create_date', models.DateField(default=datetime.date.today, verbose_name='Date')), ('create_date', models.DateField(default=datetime.date.today, verbose_name='Date')),
('user_owner', models.TextField(default='', max_length=40)),
('type', models.IntegerField(choices=[(1, 'Potrzebuje'), (2, 'Oddam')], default='')), ('type', models.IntegerField(choices=[(1, 'Potrzebuje'), (2, 'Oddam')], default='')),
('offer', models.IntegerField(choices=[(1, 'Usługa'), (2, 'Przedmiot')], default='')), ('offer', models.IntegerField(choices=[(1, 'Usługa'), (2, 'Przedmiot')], default='')),
('title', models.TextField(default='', max_length=40)), ('title', models.TextField(default='', max_length=40)),
('description', models.TextField(default='', max_length=6000)), ('description', models.TextField(default='', max_length=6000)),
('place', models.TextField(default='', max_length=40)), ('place', models.TextField(default='', max_length=40)),
('keywords', models.TextField(default='', max_length=6000)), ('keywords', models.TextField(default='', max_length=6000)),
('user_iden', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
], ],
), ),
] ]

View File

@ -1,4 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User
import datetime import datetime
TYPE_T = ( TYPE_T = (
@ -10,11 +12,12 @@ TYPE_O = (
(1,'Usługa'), (1,'Usługa'),
(2,'Przedmiot'), (2,'Przedmiot'),
) )
class Product(models.Model): class Product(models.Model):
active = models.BooleanField(default=True) active = models.BooleanField(default=True)
picture = models.ImageField(null=True, blank=True, upload_to="images/") picture = models.ImageField(null=True, blank=True, upload_to="images/")
create_date = models.DateField(("Date"), default=datetime.date.today) create_date = models.DateField(("Date"), default=datetime.date.today)
user_owner = models.TextField(max_length=40, blank=False, default="") user_iden = models.ForeignKey(User, on_delete=models.CASCADE)
type = models.IntegerField(choices = TYPE_T, blank=False, default="") type = models.IntegerField(choices = TYPE_T, blank=False, default="")
offer = models.IntegerField(choices = TYPE_O, blank=False, default="") offer = models.IntegerField(choices = TYPE_O, blank=False, default="")
title = models.TextField(max_length=40, blank=False, default="") title = models.TextField(max_length=40, blank=False, default="")

View File

@ -16,7 +16,7 @@
<!--================End Categories Banner Area =================--> <!--================End Categories Banner Area =================-->
<!--================Register Area =================--> <!--================Register Area =================-->
<form action="{% url 'Dodawanie' %}" method="POST" enctype="multipart/form-data"> <form action="{% url 'add_offer' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.media }} {{ form.media }}
{{ form.as_p }} {{ form.as_p }}

View File

@ -0,0 +1,135 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<body>
<!--================Categories Banner Area =================-->
<section class="solid_banner_area">
<div class="container">
<div class="solid_banner_inner">
<h3>Utwórz nowe konto</h3>
</div>
</div>
</section>
<!--================End Categories Banner Area =================-->
<!--================Register Area =================-->
<form action="{% url 'create_user' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.media }}
{{ form.as_p }}
<section class="track_area p_100">
<div class="container">
<div class="track_inner">
<form class="track_form row">
<div class="col-lg-12 form-group">
<label for="name">Email: <span>*</span></label>
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="email">
</div>
<div class="col-lg-12 form-group">
<label for="name">Hasło: <span>*</span></label>
<input type="password" class="form-control" id="name" aria-describedby="name" placeholder="" name="password">
</div>
<div class="col-lg-12 form-group">
<input type="submit" class="btn btn-primary update_btn" value="Rejestruj">
</div>
</form>
</div>
</div>
</section>
</form>
<!--================End Track Area =================-->
<!--================End Register Area =================-->
<!--================Footer Area =================-->
<footer class="footer_area">
<div class="container">
<div class="footer_widgets">
<div class="row">
<div class="col-lg-4 col-md-4 col-6">
<aside class="f_widget f_about_widget">
<img src="img/logo.png" alt="">
<p>Persuit is a Premium PSD Template. Best choice for your online store. Let purchase it to enjoy now</p>
<h6>Social:</h6>
<ul>
<li><a href="#"><i class="social_facebook"></i></a></li>
<li><a href="#"><i class="social_twitter"></i></a></li>
<li><a href="#"><i class="social_pinterest"></i></a></li>
<li><a href="#"><i class="social_instagram"></i></a></li>
<li><a href="#"><i class="social_youtube"></i></a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_info_widget">
<div class="f_w_title">
<h3>Information</h3>
</div>
<ul>
<li><a href="#">About us</a></li>
<li><a href="#">Delivery information</a></li>
<li><a href="#">Terms & Conditions</a></li>
<li><a href="#">Help Center</a></li>
<li><a href="#">Returns & Refunds</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_service_widget">
<div class="f_w_title">
<h3>Customer Service</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_extra_widget">
<div class="f_w_title">
<h3>Extras</h3>
</div>
<ul>
<li><a href="#">Brands</a></li>
<li><a href="#">Gift Vouchers</a></li>
<li><a href="#">Affiliates</a></li>
<li><a href="#">Specials</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_account_widget">
<div class="f_w_title">
<h3>My Account</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
</ul>
</aside>
</div>
</div>
</div>
<div class="footer_copyright">
<h5>© <script>document.write(new Date().getFullYear());</script> <!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by <a href="https://colorlib.com" target="_blank">Colorlib</a>. Downloaded from <a href="https://themeslab.org/" target="_blank">Themeslab</a>
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</h5>
</div>
</div>
</footer>
<!--================End Footer Area =================-->
</body>
</html>
{% endblock %}

View File

@ -79,7 +79,7 @@
</div> </div>
</div> </div>
<div class="col-lg-12 form-group"> <div class="col-lg-12 form-group">
<input type="submit" class="btn btn-primary update_btn" value="Dodaj"> <input type="submit" class="btn btn-primary update_btn" value="Edytuj">
</div> </div>
</form> </form>
</div> </div>

View File

@ -0,0 +1,144 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<body>
<!--================Categories Banner Area =================-->
<section class="solid_banner_area">
<div class="container">
<div class="solid_banner_inner">
<h3>Zaloguj się</h3>
</div>
</div>
</section>
<!--================End Categories Banner Area =================-->
<!--================Register Area =================-->
<form action="{% url 'login' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.media }}
{{ form.as_p }}
<input type="hidden" name="email" value="">
<input type="hidden" name="password" value="">
<section class="track_area p_100">
<div class="container">
<div class="track_inner">
<form class="track_form row">
<div class="col-lg-12 form-group">
<label for="name">Email: <span>*</span></label>
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="email">
</div>
<div class="col-lg-12 form-group">
<label for="name">Hasło: <span>*</span></label>
<input type="password" class="form-control" id="name" aria-describedby="name" placeholder="" name="password">
</div>
<div class="col-lg-12 form-group">
<input type="submit" class="btn btn-primary update_btn" value="Logowanie">
</div>
<div class="col-lg-12 form-group">
<label for="name">Jeśli nie masz konta możesz je utworzyć tutaj:</label> <br>
<a href="create_user"><button type="button" class="btn btn-primary update_btn">REJESTRACJA</button></a>
</div>
</form>
</div>
</div>
</section>
</form>
<!--================End Track Area =================-->
<!--================End Register Area =================-->
<!--================Footer Area =================-->
<footer class="footer_area">
<div class="container">
<div class="footer_widgets">
<div class="row">
<div class="col-lg-4 col-md-4 col-6">
<aside class="f_widget f_about_widget">
<img src="img/logo.png" alt="">
<p>Persuit is a Premium PSD Template. Best choice for your online store. Let purchase it to enjoy now</p>
<h6>Social:</h6>
<ul>
<li><a href="#"><i class="social_facebook"></i></a></li>
<li><a href="#"><i class="social_twitter"></i></a></li>
<li><a href="#"><i class="social_pinterest"></i></a></li>
<li><a href="#"><i class="social_instagram"></i></a></li>
<li><a href="#"><i class="social_youtube"></i></a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_info_widget">
<div class="f_w_title">
<h3>Information</h3>
</div>
<ul>
<li><a href="#">About us</a></li>
<li><a href="#">Delivery information</a></li>
<li><a href="#">Terms & Conditions</a></li>
<li><a href="#">Help Center</a></li>
<li><a href="#">Returns & Refunds</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_service_widget">
<div class="f_w_title">
<h3>Customer Service</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_extra_widget">
<div class="f_w_title">
<h3>Extras</h3>
</div>
<ul>
<li><a href="#">Brands</a></li>
<li><a href="#">Gift Vouchers</a></li>
<li><a href="#">Affiliates</a></li>
<li><a href="#">Specials</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_account_widget">
<div class="f_w_title">
<h3>My Account</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
</ul>
</aside>
</div>
</div>
</div>
<div class="footer_copyright">
<h5>© <script>document.write(new Date().getFullYear());</script> <!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by <a href="https://colorlib.com" target="_blank">Colorlib</a>. Downloaded from <a href="https://themeslab.org/" target="_blank">Themeslab</a>
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</h5>
</div>
</div>
</footer>
<!--================End Footer Area =================-->
</body>
</html>
{% endblock %}

View File

@ -9,6 +9,7 @@
<section class="solid_banner_area"> <section class="solid_banner_area">
<div class="container"> <div class="container">
<div class="solid_banner_inner"> <div class="solid_banner_inner">
<h5>{{ username }}
<h3>Moje ogłoszenia</h3> <h3>Moje ogłoszenia</h3>
</div> </div>
</div> </div>
@ -61,6 +62,7 @@
<p>No polls are available.</p> <p>No polls are available.</p>
{% endif %} {% endif %}
</div> </div>
<br><a href="delete_user"><button type="button" class="btn btn-danger pull-right">Usuń Konto</button></a>
</div> </div>
<form action="{% url 'filter' %}" method="post"> <form action="{% url 'filter' %}" method="post">

View File

@ -23,8 +23,8 @@
</div> </div>
<ul class="navbar-nav justify-content-end"> <ul class="navbar-nav justify-content-end">
<li class="search_icon"><a href="#"><i class="icon-magnifier icons"></i></a></li> <li class="search_icon"><a href="#"><i class="icon-magnifier icons"></i></a></li>
<li class="user_icon"><a href="/homepage/Mojeogloszenia"><i class="icon-user icons"></i></a></li> <li class="user_icon"><a href="/homepage/my_offer"><i class="icon-user icons"></i></a></li>
<li ><a href="/homepage/Dodawanie"><img src="{% static "plus.png"%}" height="20"/></a></li> <li ><a href="/homepage/add_offer"><img src="{% static "plus.png"%}" height="20"/></a></li>
</ul> </ul>
</nav> </nav>
</div> </div>

View File

@ -9,9 +9,14 @@ urlpatterns = [
path('contact', views.contact, name='contact'), path('contact', views.contact, name='contact'),
path('regulamin',views.regulamin, name='regulamin'), path('regulamin',views.regulamin, name='regulamin'),
path('filter', views.filter, name='filter'), path('filter', views.filter, name='filter'),
path('Dodawanie', views.Dodawanie, name='Dodawanie'), path('add_offer', views.add_offer, name='add_offer'),
path('Mojeogloszenia', views.Mojeogloszenia, name='Mojeogloszenia'), path('my_offer', views.my_offer, name='my_offer'),
path('<int:offer_id>/delete_offer', views.delete_offer, name='delete_offer'), path('<int:offer_id>/delete_offer', views.delete_offer, name='delete_offer'),
path('<int:offer_id>/edit_offer', views.edit_offer, name='edit_offer'), path('<int:offer_id>/edit_offer', views.edit_offer, name='edit_offer'),
path('create_user', views.create_user, name='create_user'),
path('login', views.login, name='login'),
path('delete_user', views.delete_user, name='delete_user'),
path('<int:user_id>/delete_user', views.delete_user, name='delete_user'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -1,7 +1,11 @@
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.urls import reverse from django.urls import reverse
from django.template import loader 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
@ -11,7 +15,7 @@ import datetime
def index(request): def index(request):
all_product = Product.objects.all all_product = Product.objects.filter(active = True)
template = loader.get_template('homepage/index.html') template = loader.get_template('homepage/index.html')
types = TYPE_T types = TYPE_T
types_o = TYPE_O types_o = TYPE_O
@ -32,16 +36,17 @@ def index(request):
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
def contact(request): def contact(request):
return render(request , 'homepage/contact.html') return render(request , 'homepage/contact.html')
def regulamin(request): def regulamin(request):
return render(request, 'homepage/regulamin.html') return render(request, 'homepage/regulamin.html')
def Mojeogloszenia(request): def my_offer(request):
all_product = Product.objects.filter(user_owner = "jedrzejklepacki@wp.pl", active = True).order_by('create_date') if request.user.is_authenticated:
template = loader.get_template('homepage/Mojeogloszenia.html') all_product = Product.objects.filter(user_iden = request.user.id, active = True).order_by('create_date')
username = request.user.email
template = loader.get_template('homepage/my_offer.html')
types = TYPE_T types = TYPE_T
types_o = TYPE_O types_o = TYPE_O
place_local = "" place_local = ""
@ -58,8 +63,11 @@ def Mojeogloszenia(request):
'types_o': types_o, 'types_o': types_o,
'usluga_local': usluga_local, 'usluga_local': usluga_local,
'przedmiot_local': przedmiot_local, 'przedmiot_local': przedmiot_local,
'username': username
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
else:
return redirect(login)
def filter(request): def filter(request):
@ -108,7 +116,8 @@ def filter(request):
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
def Dodawanie(request): def add_offer(request):
if request.user.is_authenticated:
if request.method == 'POST': if request.method == 'POST':
place_local = request.POST['place'] place_local = request.POST['place']
type_local = request.POST['type'] type_local = request.POST['type']
@ -123,7 +132,7 @@ def Dodawanie(request):
product = Product( product = Product(
picture = pic_local, picture = pic_local,
create_date = data_local, create_date = data_local,
user_owner = "jedrzejklepacki@wp.pl", user_iden = request.user,
type = int(type_local), type = int(type_local),
offer = int(offer_local), offer = int(offer_local),
title = title_local, title = title_local,
@ -132,15 +141,17 @@ def Dodawanie(request):
keywords = "", keywords = "",
) )
product.save() product.save()
return redirect(Mojeogloszenia) return redirect(my_offer)
return render(request , 'homepage/Dodawanie.html') return render(request , 'homepage/add_offer.html')
else:
return redirect(login)
def delete_offer(request, offer_id): def delete_offer(request, offer_id):
instance = Product.objects.get(id=offer_id) instance = Product.objects.get(id=offer_id)
instance.active = False instance.active = False
instance.save() instance.save()
return redirect(Mojeogloszenia) return redirect(my_offer)
def edit_offer(request, offer_id): def edit_offer(request, offer_id):
instance = Product.objects.get(id=offer_id) instance = Product.objects.get(id=offer_id)
@ -170,5 +181,58 @@ def edit_offer(request, offer_id):
instance.keywords = "" instance.keywords = ""
instance.save() instance.save()
return redirect(Mojeogloszenia) return redirect(my_offer)
return render(request , 'homepage/edycja_ogloszenia.html', context) return render(request , 'homepage/edycja_ogloszenia.html', context)
def create_user(request):
if request.method == 'POST':
User = get_user_model()
email = request.POST['email']
password = request.POST['password']
if User.objects.filter(email=email).exists():
messages.error(request,'Ten adres e-mail jest już używany')
return redirect('create_user')
else:
user = User(
username = email,
email = email,
is_active = True,
is_staff = False
)
user.save()
user.set_password(password)
user.save()
messages.success(request,'Gratulacje, teraz możesz się zalogować!')
return redirect(my_offer)
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.save()
messages.success(request,'Konto skasowane!')
return redirect(index)
def edit_user(request, user_id):
return True
def login(request):
if request.method == 'POST':
username = request.POST['email']
password = request.POST['password']
user = authenticate(request, username=username, password=password, is_active=True)
if user is not None:
auth.login(request,user)
messages.success(request, 'Jesteś zalogowany!')
return redirect(my_offer)
else:
messages.error(request,'Nieprawidłowe dane logowania!')
return redirect(login)
return render(request , 'homepage/login.html')
def logout_user(request):
if request.method == 'POST':
auth.logout(request)
messages.success(request, 'Zostałeś wylogowany!')
return render(request, index)

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB