diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/djangosite.iml b/.idea/djangosite.iml new file mode 100644 index 0000000..2144e6c --- /dev/null +++ b/.idea/djangosite.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ee3c054 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..86d517c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/djangosite/__pycache__/__init__.cpython-310.pyc b/djangosite/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..28cb742 Binary files /dev/null and b/djangosite/__pycache__/__init__.cpython-310.pyc differ diff --git a/djangosite/__pycache__/settings.cpython-310.pyc b/djangosite/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..3fd4b2a Binary files /dev/null and b/djangosite/__pycache__/settings.cpython-310.pyc differ diff --git a/djangosite/__pycache__/urls.cpython-310.pyc b/djangosite/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..16aa2d2 Binary files /dev/null and b/djangosite/__pycache__/urls.cpython-310.pyc differ diff --git a/djangosite/__pycache__/wsgi.cpython-310.pyc b/djangosite/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..4558ee6 Binary files /dev/null and b/djangosite/__pycache__/wsgi.cpython-310.pyc differ diff --git a/djangosite/settings.py b/djangosite/settings.py index 8604a8d..f8cfd29 100644 --- a/djangosite/settings.py +++ b/djangosite/settings.py @@ -27,6 +27,10 @@ DEBUG = True ALLOWED_HOSTS = [] +AUTH_USER_MODEL = 'main.User' +LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = '/' +REGISTER_REDIRECT_URL = '/' # Application definition @@ -77,11 +81,11 @@ WSGI_APPLICATION = 'djangosite.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'django', - 'USER': 'dhaverd', - 'PASSWORD': 'Dha.Verd506763', - 'HOST': '192.168.0.105', - 'PORT': 3306, + 'NAME': 'workout', + 'USER': 'root', + 'PASSWORD': 'root', + 'HOST': 'localhost', + 'PORT': 3307, }, 'workout': { 'ENGINE': 'django.db.backends.mysql', @@ -131,7 +135,7 @@ USE_TZ = True STATIC_URL = 'static/' STATICFILES_DIRS = [ - BASE_DIR / "ststic", + BASE_DIR / "static", ] # Default primary key field type diff --git a/main/__pycache__/__init__.cpython-310.pyc b/main/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..367fd82 Binary files /dev/null and b/main/__pycache__/__init__.cpython-310.pyc differ diff --git a/main/__pycache__/admin.cpython-310.pyc b/main/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..0d99e5a Binary files /dev/null and b/main/__pycache__/admin.cpython-310.pyc differ diff --git a/main/__pycache__/apps.cpython-310.pyc b/main/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..073576e Binary files /dev/null and b/main/__pycache__/apps.cpython-310.pyc differ diff --git a/main/__pycache__/forms.cpython-310.pyc b/main/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..9f7126a Binary files /dev/null and b/main/__pycache__/forms.cpython-310.pyc differ diff --git a/main/__pycache__/models.cpython-310.pyc b/main/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..e4cf7c0 Binary files /dev/null and b/main/__pycache__/models.cpython-310.pyc differ diff --git a/main/__pycache__/urls.cpython-310.pyc b/main/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..3d0394e Binary files /dev/null and b/main/__pycache__/urls.cpython-310.pyc differ diff --git a/main/__pycache__/views.cpython-310.pyc b/main/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..20c7122 Binary files /dev/null and b/main/__pycache__/views.cpython-310.pyc differ diff --git a/main/admin.py b/main/admin.py index ea5d68b..75541b1 100644 --- a/main/admin.py +++ b/main/admin.py @@ -1,3 +1,9 @@ from django.contrib import admin +from django.contrib.auth import get_user_model +from django.contrib.auth.admin import UserAdmin -# Register your models here. +User = get_user_model() + +@admin.register(User) +class UserAdmin(UserAdmin): + pass diff --git a/main/forms.py b/main/forms.py new file mode 100644 index 0000000..5c70354 --- /dev/null +++ b/main/forms.py @@ -0,0 +1,17 @@ +from django import forms +from django.contrib.auth import get_user_model +from django.contrib.auth.forms import UserCreationForm +from django.utils.translation import gettext_lazy as _ + +User = get_user_model() + +class UserCreationForm(UserCreationForm): + email = forms.EmailField( + label=_("Email"), + max_length=254, + widget=forms.EmailInput(attrs={'autocomplete': 'email'}) + ) + + class Meta(UserCreationForm.Meta): + model = User + fields = ("username", "email") diff --git a/main/migrations/0001_initial.py b/main/migrations/0001_initial.py new file mode 100644 index 0000000..0b17432 --- /dev/null +++ b/main/migrations/0001_initial.py @@ -0,0 +1,44 @@ +# Generated by Django 4.1.4 on 2022-12-20 09:23 + +import django.contrib.auth.models +import django.contrib.auth.validators +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), + ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/main/migrations/__pycache__/0001_initial.cpython-310.pyc b/main/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..86667df Binary files /dev/null and b/main/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/main/migrations/__pycache__/__init__.cpython-310.pyc b/main/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..382f0be Binary files /dev/null and b/main/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/main/models.py b/main/models.py index fd18c6e..bd8023d 100644 --- a/main/models.py +++ b/main/models.py @@ -1,3 +1,7 @@ +from django.contrib.auth.models import AbstractUser from django.db import models + # Create your models here. +class User(AbstractUser): + pass diff --git a/main/static/main/getData1.php b/main/static/main/getData1.php new file mode 100644 index 0000000..6dade8e --- /dev/null +++ b/main/static/main/getData1.php @@ -0,0 +1,59 @@ +"; + echo '' . $row["week"] . ''; + echo ""; + echo ""; + echo '[' . $row["date"] . '] ' . $row["day_name"] . ''; + echo ""; + echo ''; + echo 'Упражнение'; + echo 'Группа мышц'; + echo 'Время/подходы'; + echo 'Вес'; + $last_day = $row["day_name"]; + $day_count = 1; + } + if ($row["day_name"] != $last_day) { + $last_day = $row["day_name"]; + echo ""; + echo '[' . $row["date"] . '] ' . $row["day_name"] . ''; + echo ""; + $row_count = 0; + } + $tr = ''; + if ($row_count % 2 != 0) { + $tr = ''; + } else { + $tr = ''; + } + echo $tr; + echo ''. $row["exercise"] .''; + echo '' . $row["muscle_group_name"] . ''; + echo '' . $row["sets_count"] . ''; + echo '' . $row["weigth"] . ''; + echo ''; + $row_count = $row_count + 1; + } + //echo "Итого:" . mysqli_num_rows($result) . ""; + mysqli_free_result($result); + } else{ + echo "Ошибка: " . mysqli_error($conn); + } + mysqli_close($conn); + +?> \ No newline at end of file diff --git a/main/static/main/getData2.php b/main/static/main/getData2.php new file mode 100644 index 0000000..3ccbf3a --- /dev/null +++ b/main/static/main/getData2.php @@ -0,0 +1,59 @@ +"; + echo '' . $row["week"] . ''; + echo ""; + echo ""; + echo '[' . $row["date"] . '] ' . $row["day_name"] . ''; + echo ""; + echo ''; + echo 'Упражнение'; + echo 'Группа мышц'; + echo 'Время/подходы'; + echo 'Вес'; + $last_day = $row["day_name"]; + $day_count = 1; + } + if ($row["day_name"] != $last_day) { + $last_day = $row["day_name"]; + echo ""; + echo '[' . $row["date"] . '] ' . $row["day_name"] . ''; + echo ""; + $row_count = 0; + } + $tr = ''; + if ($row_count % 2 != 0) { + $tr = ''; + } else { + $tr = ''; + } + echo $tr; + echo ''. $row["exercise"] .''; + echo '' . $row["muscle_group_name"] . ''; + echo '' . $row["sets_count"] . ''; + echo '' . $row["weigth"] . ''; + echo ''; + $row_count = $row_count + 1; + } + //echo "Итого:" . mysqli_num_rows($result) . ""; + mysqli_free_result($result); + } else{ + echo "Ошибка: " . mysqli_error($conn); + } + mysqli_close($conn); + +?> \ No newline at end of file diff --git a/main/static/main/src/img/Ragnamod.jpg b/main/static/main/src/img/Ragnamod.jpg new file mode 100644 index 0000000..4c19e12 Binary files /dev/null and b/main/static/main/src/img/Ragnamod.jpg differ diff --git a/main/static/main/src/img/Ragnamod2.jpg b/main/static/main/src/img/Ragnamod2.jpg new file mode 100644 index 0000000..97841a4 Binary files /dev/null and b/main/static/main/src/img/Ragnamod2.jpg differ diff --git a/main/static/main/src/scripts/login.js b/main/static/main/src/scripts/login.js index aa34de8..2f52809 100644 --- a/main/static/main/src/scripts/login.js +++ b/main/static/main/src/scripts/login.js @@ -12,8 +12,8 @@ $("#form").on("submit", function(){ $('body').on('click', '#password-checkbox', function(){ if ($(this).is(':checked')){ - $('#password').attr('type', 'text'); + $('#id_password').attr('type', 'text'); } else { - $('#password').attr('type', 'password'); + $('#id_password').attr('type', 'password'); } }); \ No newline at end of file diff --git a/main/static/main/src/scripts/signin.js b/main/static/main/src/scripts/signin.js index 2c3f77e..c251ed1 100644 --- a/main/static/main/src/scripts/signin.js +++ b/main/static/main/src/scripts/signin.js @@ -12,10 +12,12 @@ $("#form").on("submit", function(){ $('body').on('click', '#password-checkbox', function(){ if ($(this).is(':checked')){ - $('#password').attr('type', 'text'); - $('#password2').attr('type', 'text'); + $('#id_password1').attr('type', 'text'); + $('#id_password2').attr('type', 'text'); } else { - $('#password').attr('type', 'password'); - $('#password2').attr('type', 'password'); + $('#id_password1').attr('type', 'password'); + $('#id_password2').attr('type', 'password'); } -}); \ No newline at end of file +}); + +$('#id_email').after('
'); \ No newline at end of file diff --git a/main/static/main/src/scripts/workout.js b/main/static/main/src/scripts/workout.js index 4afe1d6..6197a38 100644 --- a/main/static/main/src/scripts/workout.js +++ b/main/static/main/src/scripts/workout.js @@ -18,7 +18,7 @@ function getData() { } else { var username = $('#nickname-input').val().trim(); $.ajax({ - url:"getData1.php", + url:"main/templates/getData1.php", type: 'POST', data: {user: username}, success: function(msg){ @@ -35,7 +35,7 @@ function getData() { } }); $.ajax({ - url:"getData2.php", + url:"main/templates/getData2.php", type: 'POST', data: {user: username}, success: function(msg2){ diff --git a/main/static/main/src/styles/style.css b/main/static/main/src/styles/style.css index 50e0c21..7587a85 100644 --- a/main/static/main/src/styles/style.css +++ b/main/static/main/src/styles/style.css @@ -137,9 +137,19 @@ h2 { font-size: 16px; } +.minecraft-vanilla { + width: 50%; + border-radius: 20px; +} + .zomboid { width: 50%; - border-radius: 10%; + border-radius: 20px; +} + +.ragnamod { + width: 50%; + border-radius: 20px; } .image-content { @@ -154,11 +164,6 @@ h2 { height: 110px; } -.minecraft-vanilla { - width: 50%; - border-radius: 10%; -} - .fixed nav a:hover { color: #E0E0E0; background-color: #609A21; @@ -327,7 +332,7 @@ h2 { padding-bottom: 10px; } -.login-form { +.login-form, .reset-form { width: 50%; text-align: center; grid-area: login-form; @@ -390,11 +395,15 @@ h2 { color: #E0E0E0; } +.auth-form-reg .password-label { + margin-right: 5em; +} + .signin-main { padding-left: 10px; width: 97%; display: grid; - grid-template-columns: 35% 60% 5%; + grid-template-columns: 30% 60% 10%; grid-template-areas: "signin-left signin-form signin-right"; } @@ -407,8 +416,8 @@ h2 { } .signin-form { - width: 50%; - text-align: center; + width: 70%; + text-align: right; grid-area: signin-form; padding-bottom: 20px; } @@ -444,4 +453,54 @@ h2 { #wt2 { display: none; +} + +.auth-section { + background-color: #424242; + margin-top: 10px; + padding: 10px; + text-align: right; + font-size: 20px; +} + +#login-link { + padding-right: 20px; +} + +#registration-link { + padding-right: 10px; +} + +.auth-form label, .auth-form-reg label, .reset-form label { + color: #E0E0E0; + font-family: segoe print; + font-size: 16px; +} + +.auth-form input, .auth-form-reg input, .reset-form input { + font-family: Arial; + font-size: 16px; +} + +#id_username, #id_password, #id_password1, #id_password2, #id_email { + margin-left: 5px; + margin-top: 10px; +} + +.helptext { + display: none; +} + +.usernick { + margin-right: 10px; +} + +.forgot-pass-link { + text-align: center; + margin-bottom: 5px; +} + +.forgot-pass-link a { + font-family: segoe print; + font-size: 16px; } \ No newline at end of file diff --git a/main/static/main/src/styles/styleMobile.css b/main/static/main/src/styles/styleMobile.css index 6df1f62..c3a1732 100644 --- a/main/static/main/src/styles/styleMobile.css +++ b/main/static/main/src/styles/styleMobile.css @@ -124,9 +124,19 @@ h2 { font-size: 14px; } +.minecraft-vanilla { + width: 50%; + border-radius: 20px; +} + .zomboid { width: 50%; - border-radius: 10%; + border-radius: 20px; +} + +.ragnamod { + width: 50%; + border-radius: 20px; } .image-content { @@ -142,11 +152,6 @@ h2 { height: 100px; } -.minecraft-vanilla { - width: 50%; - border-radius: 10%; -} - .default nav a:hover { color: #E0E0E0; background-color: #609A21; @@ -309,7 +314,7 @@ h2 { padding-bottom: 10px; } -.login-form { +.login-form, .reset-form { width: 50%; text-align: center; grid-area: login-form; @@ -372,11 +377,15 @@ h2 { color: #E0E0E0; } +.auth-form-reg .password-label { + margin-right: 5em; +} + .signin-main { padding-left: 10px; width: 97%; display: grid; - grid-template-columns: 35% 60% 5%; + grid-template-columns: 30% 60% 10%; grid-template-areas: "signin-left signin-form signin-right"; } @@ -389,7 +398,7 @@ h2 { } .signin-form { - width: 50%; + width: 70%; text-align: center; grid-area: signin-form; padding-bottom: 20px; @@ -425,4 +434,54 @@ h2 { #wt2 { display: none; +} + +.auth-section{ + background-color: #424242; + margin-top: 10px; + padding: 10px; + text-align: right; + font-size: 12px; +} + +#login-link { + padding-right: 20px; +} + +#registration-link { + padding-right: 10px; +} + +.auth-form label, .auth-form-reg label, .reset-form label { + color: #E0E0E0; + font-family: segoe print; + font-size: 16px; +} + +.auth-form input, .auth-form-reg input, .reset-form input { + font-family: Arial; + font-size: 14px; +} + +#id_username, #id_password, #id_password1, #id_password2, #id_email { + margin-left: 5px; + margin-top: 10px; +} + +.helptext { + display: none; +} + +.usernick { + margin-right: 10px; +} + +.forgot-pass-link { + text-align: center; + margin-bottom: 5px; +} + +.forgot-pass-link a { + font-family: segoe print; + font-size: 14px; } \ No newline at end of file diff --git a/main/templates/main/login.html b/main/templates/main/login.html deleted file mode 100644 index f0db589..0000000 --- a/main/templates/main/login.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - Dhaverd - - - - - - -
- -
-

Вход

- -
-
- - - - - \ No newline at end of file diff --git a/main/templates/main/servers.html b/main/templates/main/servers.html index 3bfba7b..ddce89e 100644 --- a/main/templates/main/servers.html +++ b/main/templates/main/servers.html @@ -13,6 +13,15 @@

+
+

Minecraft 1.16.5 RagnaMod VI

+

IP: 176.114.129.4:25565

+ + +
+
+

Project Zomboid

IP: 176.114.129.4:16261

diff --git a/main/templates/main/signin.html b/main/templates/main/signin.html deleted file mode 100644 index 023136d..0000000 --- a/main/templates/main/signin.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - Dhaverd - - - - - - -
- - -
- - - - - \ No newline at end of file diff --git a/main/templates/main/temp.html b/main/templates/main/temp.html index 19016ce..0816e2a 100644 --- a/main/templates/main/temp.html +++ b/main/templates/main/temp.html @@ -8,22 +8,30 @@ - {% block javascripts %}{% endblock %}
+
+ {% if user.is_authenticated %} + {{user}} + Выход + {% else %} + Вход + Регистрация + {% endif %}
{% block maincontent %}{% endblock %}
@@ -32,5 +40,6 @@
+ {% block javascripts %}{% endblock %} \ No newline at end of file diff --git a/main/templates/main/workout.html b/main/templates/main/workout.html index c8bf3f7..68d02d3 100644 --- a/main/templates/main/workout.html +++ b/main/templates/main/workout.html @@ -4,22 +4,27 @@ {% block maincontent %}

Программа тренировок

-
-

Для просмотра иформации введите ник:

- + {% if user.is_authenticated %} +

Раздел в разработке!

+
+

Для просмотра иформации введите ник:

+ +
+ +
+ +

- -
- -
-
- -
+ +
+ {% else %} +

Для просмотра информации войдите или зарегистрируйтесь!

+ {% endif %}
{% endblock %} {% block titletext %}Dhaverd - Workout{% endblock %} {% block javascripts %} - + {% endblock %} \ No newline at end of file diff --git a/main/templates/registration/login.html b/main/templates/registration/login.html new file mode 100644 index 0000000..c588341 --- /dev/null +++ b/main/templates/registration/login.html @@ -0,0 +1,27 @@ +{% extends 'main/temp.html' %} +{% load static %} + +{% block maincontent %} +
+

Вход

+
+ + + +
+ +
+{% endblock %} +{% block titletext %}Dhaverd - Login{% endblock %} + +{% block javascripts %} + + +{% endblock %} \ No newline at end of file diff --git a/main/templates/registration/password_reset_form.html b/main/templates/registration/password_reset_form.html new file mode 100644 index 0000000..3faaf5a --- /dev/null +++ b/main/templates/registration/password_reset_form.html @@ -0,0 +1,20 @@ +{% extends 'main/temp.html' %} +{% load static %} + +{% block maincontent %} +
+

Восстановление пароля

+
+ +
+
+ {{ form }} + {% csrf_token %} + +
+
+ +
+
+{% endblock %} +{% block titletext %}Dhaverd - Reset Password{% endblock %} \ No newline at end of file diff --git a/main/templates/registration/signin.html b/main/templates/registration/signin.html new file mode 100644 index 0000000..348227b --- /dev/null +++ b/main/templates/registration/signin.html @@ -0,0 +1,26 @@ +{% extends 'main/temp.html' %} +{% load static %} + +{% block maincontent %} +
+

Регистрация

+
+ + + +
+
+{% endblock %} +{% block titletext %}Dhaverd - Registration{% endblock %} + +{% block javascripts %} + + +{% endblock %} \ No newline at end of file diff --git a/main/urls.py b/main/urls.py index 8d9d70f..fdc699d 100644 --- a/main/urls.py +++ b/main/urls.py @@ -1,9 +1,15 @@ -from django.urls import path +from django.urls import path, include from . import views +from .views import Register urlpatterns = [ - path('', views.index), - path('servers', views.servers), - path('mychat', views.mychat), - path('workout', views.workout) + path('', views.index, name='index'), + path('servers', views.servers, name='servers'), + path('mychat', views.mychat, name='mychat'), + path('workout', views.workout, name='workout'), + path('login', views.login, name='login'), + path('registration', views.registration, name='registration'), + path('logout', views.logout, name='logout'), + path('', include('django.contrib.auth.urls')), + path('register/', Register.as_view(), name='register'), ] \ No newline at end of file diff --git a/main/views.py b/main/views.py index c73dc60..1dd1130 100644 --- a/main/views.py +++ b/main/views.py @@ -1,5 +1,10 @@ -from django.shortcuts import render +import django.contrib.auth +from django.contrib.auth import authenticate +from django.shortcuts import render, redirect from django.http import HttpResponse +from django.views import View + +from main.forms import UserCreationForm # Create your views here. @@ -17,3 +22,39 @@ def mychat(request): def workout(request): return render(request, 'main/workout.html') + + +def login(request): + return render(request, 'registration/login.html') + + +def registration(request): + return render(request, 'registration/signin.html') + + +def logout(request): + pass + + +class Register(View): + template_name = 'registration/signin.html' + + def get(self, request): + context = { + 'form': UserCreationForm() + } + return render(request, self.template_name, context) + + def post(self, request): + form = UserCreationForm(request.POST) + if form.is_valid(): + form.save() + username = form.cleaned_data.get('username') + password = form.cleaned_data.get('password1') + user = authenticate(username=username, password=password) + django.contrib.auth.login(request, user) + return redirect('home') + context = { + 'form': form + } + return render(request, self.template_name, context) \ No newline at end of file