mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
23 lines
923 B
Python
23 lines
923 B
Python
from django.shortcuts import render, redirect
|
|
from django.contrib.auth import authenticate, login
|
|
from django.contrib.auth.forms import AuthenticationForm
|
|
|
|
def login_view(request):
|
|
if request.method == 'POST':
|
|
form = AuthenticationForm(data=request.POST)
|
|
if form.is_valid():
|
|
username = form.cleaned_data.get('username')
|
|
password = form.cleaned_data.get('password')
|
|
user = authenticate(username=username, password=password)
|
|
if user is not None:
|
|
login(request, user)
|
|
return redirect('home') # Substitua 'home' pelo nome da sua URL inicial
|
|
else:
|
|
pass
|
|
# Mensagem de erro: Credenciais inválidas
|
|
else:
|
|
pass
|
|
# Mensagem de erro: Formulário inválido
|
|
else:
|
|
form = AuthenticationForm()
|
|
return render(request, 'login.html', {'form': form}) |