arxiv_chatbot / users /views.py
Artteiv's picture
Refactoring gemini functions (#9)
3826b3b verified
raw
history blame
1.4 kB
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")