arxiv_chatbot / users /views.py
Artteiv's picture
ok
46d747a
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:index")
else:
form = UserCreationForm()
return render(request, "users/register.html", { "form": form })
def login_view(request):
if request.user.is_authenticated:
return redirect("chat:index")
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:index")
else:
form = AuthenticationForm()
return render(request, "users/login.html", { "form": form })
def logout_view(request):
logout(request)
return redirect("chat:index")
def index_view(request):
return render(request, "users/index.html")