26 lines
682 B
Python
26 lines
682 B
Python
|
#!/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')
|