Spaces:
Runtime error
Runtime error
File size: 1,398 Bytes
3826b3b 27dbc87 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth import login, logout
# from chat.models import Chat, User
# Create your views here.
def register_view(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
login(request, form.save())
return redirect("chat:room")
else:
form = UserCreationForm()
return render(request, "users/register.html", { "form": form })
def login_view(request):
if request.user.is_authenticated:
return redirect("../chat/room.html")
if request.method == "POST":
form = AuthenticationForm(data=request.POST)
if form.is_valid():
login(request, form.get_user())
#Get chat history of user
if 'next' in request.POST:
return redirect(request.POST.get('next'))
else:
return redirect("chat.views.room")
else:
form = AuthenticationForm()
return render(request, "users/login.html", { "form": form })
def logout_view(request):
if request.method == "POST":
logout(request)
return redirect("chat:room")
def index_view(request):
return render(request, "users/index.html") |