Browse Source

Added registration

master
Jakub Škrabánek 4 years ago
parent
commit
26731945be
  1. 2
      README.md
  2. 0
      accounts/__init__.py
  3. 3
      accounts/admin.py
  4. 6
      accounts/apps.py
  5. 0
      accounts/migrations/__init__.py
  6. 3
      accounts/models.py
  7. 3
      accounts/tests.py
  8. 7
      accounts/urls.py
  9. 9
      accounts/views.py
  10. 6
      loginproject/settings.py
  11. 1
      loginproject/urls.py
  12. 12
      templates/home.html
  13. 6
      templates/registration/login.html
  14. 15
      templates/registration/password_reset_form.html
  15. 16
      templates/registration/reg.html

2
README.md

@ -26,7 +26,7 @@ Pokud používáme PyCharm přesuneme se na bod 3.
> 'DIRS': [], >>>>>> **'DIRS': [BASE_DIR / "templates"],**
8. vytvoříme si složku **templates** a uvnitř složky templates vytvoříme složku **registration**
9. ve složce registration vytvoříme soubor **login.html** (celá cesta je templates/registration/login.html)
9. ve složce registration vytvoříme soubor **login.html** (celá cesta je *templates/registration/login.html*)
```html
<!DOCTYPE html>

0
accounts/__init__.py

3
accounts/admin.py

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
accounts/apps.py

@ -0,0 +1,6 @@
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'

0
accounts/migrations/__init__.py

3
accounts/models.py

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
accounts/tests.py

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
accounts/urls.py

@ -0,0 +1,7 @@
from django.urls import path
from .views import regView
urlpatterns = [
path("reg/", regView.as_view(),name="reg")
]

9
accounts/views.py

@ -0,0 +1,9 @@
from django.shortcuts import render
from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from django.views import generic
class regView(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy("login")
template_name = "registration/reg.html"

6
loginproject/settings.py

@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-k$*jfxlrl0125n^*-548g5-a!+i@e6l2)#2gfyv^!0xi0-(*96'
SECRET_KEY = 'django-insecure-(__uc&%9#ymprsk0(9c9ykmkvc+%%wvm3*$bvz!oo+2a-3cb6r'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
]
MIDDLEWARE = [
@ -126,3 +127,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
EMAIL_FILE_PATH = BASE_DIR / "sent_email"

1
loginproject/urls.py

@ -19,6 +19,7 @@ from django.views.generic.base import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path("ucet/", include("accounts.urls")),
path("ucet/", include("django.contrib.auth.urls")),
path("",TemplateView.as_view(template_name="home.html"), name="home")
]

12
templates/home.html

@ -5,16 +5,18 @@
<title>Title</title>
</head>
<body>
<h1>Login systém</h1>
<h1>Login system</h1>
{% if user.is_authenticated %}
<div>Ahoj, {{ user.username}} </div>
<a href="{% url 'logout' %}">Odhlásit</a>
<div>ahoj, {{ user.username }} </div>
<a href="{% url 'logout' %}">Logout</a>
{% else %}
<p>Nejsi přihlášený</p>
<a href="{% url 'login'%}">Prihlasit</a>
<a href="{% url 'login' %}">Login</a>
<a href="{% url 'reg' %}">Registrace</a>
<a href="{% url 'password_reset' %}">RESET PW</a>
{% endif %}
</body>
</html>

6
templates/registration/login.html

@ -5,12 +5,12 @@
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<h1>Login</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit"> Prihlasit</button>
<button type="submit">Login</button>
</form>
<a href="/">Home</a>
</body>
</html>

15
templates/registration/password_reset_form.html

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PW reset</title>
</head>
<body>
<h1>PW reset - form</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="RESET PASSWORD">
</form>
</body>
</html>

16
templates/registration/reg.html

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration</title>
</head>
<body>
<h1>Registration</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Registration</button>
</form>
<a href="/">Home</a>
</body>
</html>
Loading…
Cancel
Save