Spaces:
Sleeping
Sleeping
File size: 1,345 Bytes
3826b3b 46d747a 3826b3b 46d747a 3826b3b 46d747a 3826b3b 46d747a 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 |
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") |