From 8df4347932b1a18159a486b821bdb598a328a29d Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 10 Aug 2018 18:55:42 -0400 Subject: [PATCH] added login page --- login/__init__.py | 0 login/admin.py | 3 +++ login/apps.py | 5 +++++ login/jinja2/login/index.html | 11 +++++++++++ login/migrations/__init__.py | 0 login/models.py | 3 +++ login/tests.py | 3 +++ login/urls.py | 12 ++++++++++++ login/views.py | 25 +++++++++++++++++++++++++ 9 files changed, 62 insertions(+) create mode 100644 login/__init__.py create mode 100644 login/admin.py create mode 100644 login/apps.py create mode 100644 login/jinja2/login/index.html create mode 100644 login/migrations/__init__.py create mode 100644 login/models.py create mode 100644 login/tests.py create mode 100644 login/urls.py create mode 100644 login/views.py 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')