41 lines
1.3 KiB
Python
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")
|