Skip to content

Commit

Permalink
add registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey-Krd committed Dec 7, 2023
1 parent 5091c41 commit 9fd58af
Show file tree
Hide file tree
Showing 36 changed files with 495 additions and 35 deletions.
21 changes: 16 additions & 5 deletions adaptive_hockey_federation/adaptive_hockey_federation/settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
from django.core.management.utils import get_random_secret_key

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = get_random_secret_key()

SECRET_KEY = 'django-insecure-))v)^p&_y!_-dsc7p)v%b@yi+#)k^34mp^ai8jc^9v)jpu2xn1'
DEBUG = True

ALLOWED_HOSTS: list = ['*']
Expand All @@ -18,6 +20,7 @@
'django.contrib.staticfiles',
'main.apps.MainConfig',
'users.apps.UsersConfig',
'core.apps.CoreConfig',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -54,7 +57,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

Expand Down Expand Up @@ -82,11 +85,19 @@
USE_TZ = True

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

LOGIN_REDIRECT_URL = 'main:main'

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'

EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'sent_emails')

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL = 'users.User'
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
path('admin/', admin.site.urls),
path('', include('main.urls', namespace='main')),
path('auth/', include('users.urls', namespace='users')),
path('auth/', include('django.contrib.auth.urls')),
]
6 changes: 6 additions & 0 deletions adaptive_hockey_federation/core/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'
8 changes: 8 additions & 0 deletions adaptive_hockey_federation/core/templatetags/user_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.filter
def addclass(field, css):
return field.as_widget(attrs={'class': css})
9 changes: 9 additions & 0 deletions adaptive_hockey_federation/core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.shortcuts import render


def page_not_found(request, exception):
return render(request, 'core/404.html', {'path': request.path}, status=404)


def csrf_failure(request, reason=''):
return render(request, 'core/403csrf.html')
1 change: 1 addition & 0 deletions adaptive_hockey_federation/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


urlpatterns = [
path('', views.main, name='main'),
path('users/', views.users, name='users'),
path('teams/<int:id>/', views.teams_id, name='teams_id'),
path('teams/', views.teams, name='teams'),
Expand Down
5 changes: 4 additions & 1 deletion adaptive_hockey_federation/main/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.shortcuts import render


# пример рендера таблиц, удалить после реализации вьюх
CONTEXT_EXAMPLE = {
'table_head': {
Expand All @@ -15,6 +14,10 @@
}


def main(request):
return render(request, 'main/main.html')


def users(request):
return render(request, 'main/users.html')

Expand Down
8 changes: 4 additions & 4 deletions adaptive_hockey_federation/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
<div class="row">
<div class="col ps-md-2 pt-2">
<div class="page-header pt-3">
{% block content %}#}
Основной текст
{% endblock %}
{% block content %}
Основной текст
{% endblock %}
</div>
</div>
</div>
</div>
<footer>
<footer class="basic border-top">
{% include 'includes/footer.html' %}
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
Expand Down
5 changes: 5 additions & 0 deletions adaptive_hockey_federation/templates/core/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block title %} Кастомная ошибка доступа {% endblock %}
{% block content %}
<h1>Custom permission denied</h1>
{% endblock %}
4 changes: 4 additions & 0 deletions adaptive_hockey_federation/templates/core/403csrf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<h1>Custom CSRF check error. 403</h1>
{% endblock %}
7 changes: 7 additions & 0 deletions adaptive_hockey_federation/templates/core/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block title %}Custom 404{% endblock %}
{% block content %}
<h1>Custom 404</h1>
<p>Страницы с адресом {{ path }} не существует</p>
<a href="{% url 'main:main' %}">Идите на главную</a>
{% endblock %}
14 changes: 14 additions & 0 deletions adaptive_hockey_federation/templates/includes/forms_errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger">
{{ error|escape }}
</div>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger">
{{ error|escape }}
</div>
{% endfor %}
{% endif %}
39 changes: 25 additions & 14 deletions adaptive_hockey_federation/templates/includes/header.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
<nav class="navbar navbar-light" style="background-color: #64c2d1;">
{% load static %}
<nav class="top-menu" style="background-color: #64c2d1;">

<div class="container">
<div class="nav justify-content-end">
<ul class="nav d-flex justify-content-start">
{% if request.user.is_authenticated %}
<div class="border border-white rounded px-2">
<i class="bi bi-circle-fill fs-3" style="color: black;"></i>
<a href="{% url 'users:profile' user.username %}">
<b class="text-xl" style="color: #340061;">{{ user.username }}</b>
</a>
</div>
<div class="border border-white rounded px-2">
<i class="bi bi-circle-fill fs-3" style="color: red;"></i>
<b class="text-xl" style="color: #340061;">Username</b>
<a href="{% url 'users:logout' %}">
<b class="text-xl" style="color: #340061;">Выйти</b>
</a>
</div>
</ul>
<ul class="nav justify-content-end">
<li class="nav-item d-flex">

<a class="nav-link border border-primary place-self-center bg-white p-0.5" href="##">
<i class="bi bi-search fs-5 p-1 bg-white" style="color: grey;"></i>
{% else %}
<div class="border border-white rounded px-2">
<i class="bi bi-circle-fill fs-3" style="color: green;"></i>
<a href="{% url 'users:login' %}">
<b class="text-xl" style="color: #340061;">Войти</b>
</a>
</li>
<li class="nav-item ms-16">
<a class="nav-link p-0" href="##">
<i class="bi bi-box-arrow-right fs-1" style="color: white;"></i>
</div>
<div class="border border-white rounded px-2">
<i class="bi bi-circle-fill fs-3" style="color: blue;"></i>
<a href="{% url 'users:signup' %}">
<b class="text-xl" style="color: #340061;">Регистрация</b>
</a>
</li>
</div>
{% endif %}
</ul>
</div>
</nav>
7 changes: 7 additions & 0 deletions adaptive_hockey_federation/templates/main/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base.html' %}
{% block title %}
Главная страница
{% endblock %}
{% block content %}
Главная страница
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% load user_filters %}
<div class="form-group row my-3">
<label for="{{ field.id_for_label }}">
{{ field.label }}
{% if field.field.required %}
<span class="required text-danger">*</span>
{% endif %}
</label>
{{ field|addclass:'form-control' }}
{% if field.help_text %}
<small
id="{{ field.id_for_label }}-help"
class="form-text text-muted">
{{ field.help_text|safe }}
</small>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-8 p-5">
<div class="card">
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block title %} Пароль изменён {% endblock %}
{% block content %}
{% include 'registration/includes/open_divs.html' %}
<div class="card-header">
Пароль изменён
</div>
<div class="card-body">
<p>Пароль изменён успешно</p>
</div>
{% include 'registration/includes/close_divs.html' %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block title %} Изменение пароля {% endblock %}
{% block content %}
{% include 'registration/includes/open_divs.html' %}
<div class="card-header">
Изменить пароль
</div>
<div class="card-body">
{% include 'includes/forms_errors.html' %}
<form method="post"
{% if action_url %}
action="{% url action_url %}">
{% endif %}
>


{% for field in form %}
{% include 'registration/includes/fields_form.html' %}
{% endfor %}
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Сменить пароль
</button>
</div>
</form>

</div>
{% include 'registration/includes/close_divs.html' %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block title %} Сброс пароля прошёл успешно {% endblock %}
{% block content %}
{% include 'registration/includes/open_divs.html' %}
<div class="card">
<form method="action" action="{% url 'users:login' %}">
<div class="form-group">
<div class="card-header">
Восстановление пароля завершено
</div>
<div class="card-body">
<p>Ваш пароль был сохранен. Используйте его для входа</p>
<div class="col-md-6 offset-md-4">
<button type='submit' class="btn btn-primary">
Войти
</button>
</div>
</div>
</div>
</form>
</div>
{% include 'registration/includes/close_divs.html' %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block title %} Новый пароль {% endblock %}
{% block content %}
{% if validlink %}
{% include 'registration/includes/open_divs.html' %}
<div class="card-body">
{% include 'includes/forms_errors.html' %}

<form method="post"
{% if action_url %}
action="{% url action_url %}">
{% endif %}
>
{% csrf_token %}

{% for field in form %}
{% include 'registration/includes/fields_form.html' %}
{% endfor %}
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Назначить новый пароль
</button>
</div>
</form>

</div>
{% else %}
<div class="card-header">
Ошибка
</div>
<div class="card-body">
<p>Ссылка сброса пароля содержит ошибку или устарела.</p>
</div>
{% endif %}
{% include 'registration/includes/close_divs.html' %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block title %} Сброс пароля прошёл успешно {% endblock %}
{% block content %}
{% include 'registration/includes/open_divs.html' %}
<div class="card-header">
Отправлено письмо
</div>
<div class="card-body">
<p>Проверьте свою почту, вам должно прийти письмо со ссылкой для восстановления пароля</p>
</div>
{% include 'registration/includes/close_divs.html' %}
{% endblock %}
Loading

0 comments on commit 9fd58af

Please sign in to comment.