summaryrefslogtreecommitdiff
path: root/apps/accounts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/accounts')
-rw-r--r--apps/accounts/__init__.py0
-rw-r--r--apps/accounts/admin.py3
-rw-r--r--apps/accounts/apps.py6
-rw-r--r--apps/accounts/migrations/__init__.py0
-rw-r--r--apps/accounts/models.py3
-rw-r--r--apps/accounts/static/accounts/login.css23
-rw-r--r--apps/accounts/templates/accounts/login.html15
-rw-r--r--apps/accounts/templates/accounts/register.html18
-rw-r--r--apps/accounts/tests.py3
-rw-r--r--apps/accounts/urls.py10
-rw-r--r--apps/accounts/views.py44
11 files changed, 125 insertions, 0 deletions
diff --git a/apps/accounts/__init__.py b/apps/accounts/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/accounts/__init__.py
diff --git a/apps/accounts/admin.py b/apps/accounts/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/apps/accounts/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/apps/accounts/apps.py b/apps/accounts/apps.py
new file mode 100644
index 0000000..bd9d60a
--- /dev/null
+++ b/apps/accounts/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class AccountsConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'apps.accounts'
diff --git a/apps/accounts/migrations/__init__.py b/apps/accounts/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/accounts/migrations/__init__.py
diff --git a/apps/accounts/models.py b/apps/accounts/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/apps/accounts/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/apps/accounts/static/accounts/login.css b/apps/accounts/static/accounts/login.css
new file mode 100644
index 0000000..252e026
--- /dev/null
+++ b/apps/accounts/static/accounts/login.css
@@ -0,0 +1,23 @@
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+}
+
+html {
+ font-size: 16px;
+}
+
+:root {
+ --bg-default: #2e2e2e;
+ --bg-action: #923737;
+ --bg-pause: #416e46;
+}
+
+body {
+ background-color: var(--bg-default);
+ font-family: 'Segoe UI', 'Roboto', sans-serif;
+ color: #e8e6e3;
+ transition: background-color 0.3s ease;
+}
+
diff --git a/apps/accounts/templates/accounts/login.html b/apps/accounts/templates/accounts/login.html
new file mode 100644
index 0000000..5f11c28
--- /dev/null
+++ b/apps/accounts/templates/accounts/login.html
@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+
+{% block title %}Login - fsweb{% endblock %}
+
+{% block content %}
+Log in.
+<form method="post">{% csrf_token %}
+ <input name="username" type="text" placeholder="username"><br>
+ <input name="password" type="text" placeholder="password"><br>
+ <button type="submit">Log In</button>
+</form>
+Don't have an account? <a href="/accounts/register">Register</a>
+<br>
+Forgot your password? Unfortunate.
+{% endblock %}
diff --git a/apps/accounts/templates/accounts/register.html b/apps/accounts/templates/accounts/register.html
new file mode 100644
index 0000000..213250f
--- /dev/null
+++ b/apps/accounts/templates/accounts/register.html
@@ -0,0 +1,18 @@
+{% extends 'base.html' %}
+
+{% block title %}Login - fsweb{% endblock %}
+
+{% block content %}
+Create account.<br>
+<form method="post">{% csrf_token %}
+ <input name="username" type="text" placeholder="username"><br>
+ <input name="password1" type="text" placeholder="password"><br>
+ <input name="password2" type="text" placeholder="password confirmation"><br>
+ <input name="email" type="text" placeholder="email (optional)"><br>
+ <button type="submit">Register</button>
+</form>
+<br>
+{{ form.errors }}
+<br>
+Already have an account? <a href="/accounts/login">Go to Login</a>
+{% endblock %}
diff --git a/apps/accounts/tests.py b/apps/accounts/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/apps/accounts/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/apps/accounts/urls.py b/apps/accounts/urls.py
new file mode 100644
index 0000000..a4cb240
--- /dev/null
+++ b/apps/accounts/urls.py
@@ -0,0 +1,10 @@
+from django.urls import path
+
+from . import views
+
+app_name = 'accounts'
+urlpatterns = [
+ path("register/", views.register_view, name="register"),
+ path("login/", views.login_view, name="login"),
+ path("logout/", views.logout_view, name="logout")
+]
diff --git a/apps/accounts/views.py b/apps/accounts/views.py
new file mode 100644
index 0000000..2027982
--- /dev/null
+++ b/apps/accounts/views.py
@@ -0,0 +1,44 @@
+from django.shortcuts import render, redirect
+from django.contrib.auth import authenticate, login, logout
+from django.contrib.auth.forms import UserCreationForm
+
+
+def login_view(request):
+ if request.method == "POST":
+ username = request.POST['username']
+ password = request.POST['password']
+ user = authenticate(request, username=username, password=password)
+ if user:
+ login(request, user)
+ return redirect('index')
+ else:
+ pass
+
+ return render(request, 'accounts/login.html', {'form': None})
+
+
+def register_view(request):
+ form = None
+
+ if request.method == 'POST':
+ form = UserCreationForm(request.POST)
+ if form.is_valid():
+ form.save()
+
+ username = request.POST.get('username')
+ password = request.POST.get('password1')
+ user = authenticate(request, username=username, password=password)
+ if user:
+ login(request, user)
+ return redirect('index')
+
+ return render(request, 'accounts/register.html', {'form': form})
+
+
+def logout_view(request):
+ if request.method == 'POST':
+ if request.user.is_authenticated:
+ logout(request)
+
+ return redirect('index')
+