1
0
Fork 0
This repository has been archived on 2025-03-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
csb-project-1/notes/views.py
2024-11-24 16:45:26 +02:00

41 lines
1.3 KiB
Python

from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.db import transaction, connection
# from notes.models import Note
@login_required()
def index(request):
user = request.user
# notes = Note.objects.filter(owner=user)
# notes_list = [ { 'time' : note.time, 'body' : note.body } for note in notes ]
# notes_list.sort(key=lambda note: note['time'])
# return render(request, 'index.html', { 'notes' : notes_list})
return render(request, 'index.html')
def login_view(request):
if request.method == 'GET':
return render(request, 'login.html')
elif request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect("index")
else:
return render(request, 'login.html', { 'login_failed' : True })
return redirect("index")
def logout_view(request):
if request.method == 'POST':
logout(request)
return redirect("index")