added login page
This commit is contained in:
parent
1b8ee3d0f3
commit
8df4347932
0
login/__init__.py
Normal file
0
login/__init__.py
Normal file
3
login/admin.py
Normal file
3
login/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
login/apps.py
Normal file
5
login/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LoginConfig(AppConfig):
|
||||
name = 'login'
|
11
login/jinja2/login/index.html
Normal file
11
login/jinja2/login/index.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Login{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Login</h1>
|
||||
<form method="post" action="{{ url('login:index') }}">
|
||||
{{ csrf_input }}
|
||||
<input type="text" placeholder="Username" name="username" maxlength="20" required/><br />
|
||||
<input type="password" placeholder="Password" name="password" maxlength="1024" required/><br />
|
||||
<input type="submit" value="Log in" name="submit"/>
|
||||
</form>
|
||||
{% endblock %}
|
0
login/migrations/__init__.py
Normal file
0
login/migrations/__init__.py
Normal file
3
login/models.py
Normal file
3
login/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
login/tests.py
Normal file
3
login/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
12
login/urls.py
Normal file
12
login/urls.py
Normal file
|
@ -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'),
|
||||
]
|
25
login/views.py
Normal file
25
login/views.py
Normal file
|
@ -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')
|
Loading…
Reference in New Issue
Block a user