require login

This commit is contained in:
2021-12-22 15:27:10 -06:00
parent 96dc7248d1
commit 92920b3b89
4 changed files with 23 additions and 15 deletions

View File

@@ -131,3 +131,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
LOGIN_URL = "/login"
LOGIN_REDIRECT_URL = ""

View File

@@ -18,12 +18,12 @@ from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from .views import welcome, user_login
from .views import welcome, login
urlpatterns = [
path("", welcome, name="home"),
path("", include("benchcoach.urls")),
path("admin/", admin.site.urls),
path("teamsnap/", include("teamsnap.urls")),
path("login", user_login, name="login"),
path("login", login, name="login"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@@ -1,13 +1,15 @@
from django.http import HttpResponse
from django.shortcuts import render,redirect, reverse, HttpResponseRedirect
from django.contrib.auth import login,authenticate
from django.contrib.auth.decorators import login_required
@login_required()
def welcome(request):
pages = ['event list', 'team list', 'venue list', 'player list', 'teamsnap list events', 'teamsnap home', 'login']
pages = ['event list', 'team list', 'venue list', 'player list', 'teamsnap home', 'login']
return render(request,'home.html',{'pages':pages})
def user_login(request):
def login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')

View File

@@ -3,17 +3,20 @@
{% block title %}Bench Coach Home{% endblock %}
{% block content %}
<form method="post" action="{% url "login" %}">
{% csrf_token %}
<div class="text-center d-flex flex-column justify-content-center align-items-center mb-4">
<form style="width: 100%; max-width: 330px; padding: 15px; margin: 0 auto;"
method="post" action="{% url "login" %}">
{% csrf_token %}
<header>Login</header>
<label>Username <span>*</span></label>
<input type="text" name="username" placeholder="Username" required="" />
<div class="help">At least 5 character</div>
<label>Password <span>*</span></label>
<input type="password" name="password" placeholder="Password" required="" />
<div class="help">Use upper and lowercase letters as well</div>
<button type="submit">Login</button>
<img class="mb-4" src="{% static "benchcoach.svg" %}" width="72" height="72"/>
<h3>Please Sign In</h3>
<input class="form-control" type="text" name="username" placeholder="Username" required=""
style="margin-bottom: -1px; border-bottom-right-radius: 0; border-bottom-left-radius: 0;"/>
<input class="form-control" type="password" name="password" placeholder="Password" required=""
style="margin-bottom: 10px; border-top-left-radius: 0; border-top-right-radius: 0;"/>
<button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
</form>
</div>
</form>