diff --git a/login/__init__.py b/login/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/login/admin.py b/login/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/login/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/login/apps.py b/login/apps.py new file mode 100644 index 0000000..be1c173 --- /dev/null +++ b/login/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LoginConfig(AppConfig): + name = 'login' diff --git a/login/jinja2/login/index.html b/login/jinja2/login/index.html new file mode 100644 index 0000000..94ba860 --- /dev/null +++ b/login/jinja2/login/index.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block title %}Login{% endblock %} +{% block content %} +

Login

+
+ {{ csrf_input }} +
+
+ +
+{% endblock %} diff --git a/login/migrations/__init__.py b/login/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/login/models.py b/login/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/login/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/login/tests.py b/login/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/login/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/login/urls.py b/login/urls.py new file mode 100644 index 0000000..191e6e0 --- /dev/null +++ b/login/urls.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +""" +Login app URL configuration. +""" +from django.urls import path + +from . import views + +app_name = 'login' +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/login/views.py b/login/views.py new file mode 100644 index 0000000..3a7e5a9 --- /dev/null +++ b/login/views.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +""" +/login app views. +""" +from django.contrib import messages +from django.shortcuts import redirect, render +from django.contrib.auth import authenticate, login + +def index(request): + """ + The login page. + """ + if request.method == "GET": + context = {} + return render(request, 'login/index.html', context) + username = request.POST['username'] + password = request.POST['password'] + user = authenticate(request, username=username, password=password) + if user is not None: + login(request, user) + messages.success(request, "Logged in") + return redirect('homepage:index') + else: + messages.error(request, "Invalid credentials") + return redirect('login:index')