diff --git a/web-app/django/VIM/apps/main/models.py b/web-app/django/VIM/apps/main/models.py index 71a8362..fd18c6e 100644 --- a/web-app/django/VIM/apps/main/models.py +++ b/web-app/django/VIM/apps/main/models.py @@ -1,3 +1,3 @@ -from django.db import models - -# Create your models here. +from django.db import models + +# Create your models here. diff --git a/web-app/django/VIM/apps/main/static/main/css/login.css b/web-app/django/VIM/apps/main/static/main/css/login.css new file mode 100644 index 0000000..ebfa293 --- /dev/null +++ b/web-app/django/VIM/apps/main/static/main/css/login.css @@ -0,0 +1,58 @@ +.login-form { + color: #435334; +} + +input { + border: 1px solid #9EB384; + border-radius: 4px; + background-color: #FAF1E4; + padding: 5px; + color: #435334; + margin: 0 10px; +} + +input:hover { + border: 1px solid #435334; + background-color: #FAF1E4; + color: #435334; +} + +input:focus { + border: 1px solid #435334; + box-shadow: 0 0 5px #9EB384; + outline: none; +} + +input::placeholder { + color: #9EB384; +} + +.btn-primary { + background-color: #435334; + border: 1px solid #435334; +} + +.btn-primary:hover { + background-color: #9EB384; + border: 1px solid #9EB384; +} + +p { + color: #435334; +} + +a { + color: #435334; + text-decoration: none; + font-weight: bold; +} + +a:hover { + color: #9EB384; + text-decoration: none; + font-weight: bold; +} + +.errorlist { + color: red; +} \ No newline at end of file diff --git a/web-app/django/VIM/apps/main/templates/registration/change_password.html b/web-app/django/VIM/apps/main/templates/registration/change_password.html new file mode 100644 index 0000000..9717814 --- /dev/null +++ b/web-app/django/VIM/apps/main/templates/registration/change_password.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %} +Login +{% endblock %} + +{% block css_files %} + +{% endblock %} + +{% block content %} +
+
+
+ {% if form.errors %} +
+ {% for field, error in form.errors.items %} + {{ error }} + {% endfor %} +
+ {% endif %} + +
+
+
+{% endblock %} + +{% block script %} +{% endblock %} \ No newline at end of file diff --git a/web-app/django/VIM/apps/main/templates/registration/login.html b/web-app/django/VIM/apps/main/templates/registration/login.html new file mode 100644 index 0000000..1a4794e --- /dev/null +++ b/web-app/django/VIM/apps/main/templates/registration/login.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %} +Login +{% endblock %} + +{% block css_files %} + +{% endblock %} + +{% block content %} +
+
+
+ {% if messages %} +
+ {% for message in messages %} + {{ message }} + {% endfor %} +
+ {% endif %} + {% if form.errors %} +
+ {% for field, error in form.errors.items %} + {{ error }} + {% endfor %} +
+ {% endif %} + + +
+
+
+{% endblock %} + +{% block script %} +{% endblock %} \ No newline at end of file diff --git a/web-app/django/VIM/apps/main/templates/registration/register.html b/web-app/django/VIM/apps/main/templates/registration/register.html new file mode 100644 index 0000000..d430f27 --- /dev/null +++ b/web-app/django/VIM/apps/main/templates/registration/register.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %} +Register +{% endblock %} + +{% block css_files %} + +{% endblock %} + +{% block content %} +
+
+
+ {% if form.errors %} +
+ {% for field, error in form.errors.items %} + {{ error }} + {% endfor %} +
+ {% endif %} + +
+
+
+{% endblock %} + +{% block script %} +{% endblock %} \ No newline at end of file diff --git a/web-app/django/VIM/apps/main/urls.py b/web-app/django/VIM/apps/main/urls.py index 14baff0..c0c300a 100644 --- a/web-app/django/VIM/apps/main/urls.py +++ b/web-app/django/VIM/apps/main/urls.py @@ -1,4 +1,5 @@ from django.urls import path +from django.contrib.auth import views as auth_views from . import views app_name = "main" @@ -6,4 +7,28 @@ urlpatterns = [ path("", views.home, name="home"), path("about/", views.about, name="about"), + path("register/", views.register, name="register"), + path( + "accounts/logout/", + auth_views.LogoutView.as_view(next_page="main:home"), + name="logout", + ), + path( + "change-password/", + auth_views.PasswordChangeView.as_view( + template_name="registration/change_password.html", + success_url="/", + ), + name="change_password", + ), + path( + "accounts/login/", + auth_views.LoginView.as_view( + template_name="registration/login.html", + redirect_authenticated_user=True, + redirect_field_name="next", + next_page="main:home", + ), + name="login", + ), ] diff --git a/web-app/django/VIM/apps/main/views.py b/web-app/django/VIM/apps/main/views.py index 70423e5..2c63e0a 100644 --- a/web-app/django/VIM/apps/main/views.py +++ b/web-app/django/VIM/apps/main/views.py @@ -1,4 +1,7 @@ +from django.contrib.auth import login from django.shortcuts import render +from django.shortcuts import redirect +from django.contrib.auth.forms import UserCreationForm def home(request): @@ -7,3 +10,16 @@ def home(request): def about(request): return render(request, "main/about.html", {"active_tab": "about"}) + + +def register(request): + if request.method == "POST": + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + return redirect("main:home") + else: + form = UserCreationForm() + + return render(request, "registration/register.html", {"form": form}) diff --git a/web-app/django/VIM/templates/base.html b/web-app/django/VIM/templates/base.html index 17493e5..28949ba 100644 --- a/web-app/django/VIM/templates/base.html +++ b/web-app/django/VIM/templates/base.html @@ -37,7 +37,21 @@
- + {% if user.is_authenticated %} + + {% else %} + + + + {% endif %}