2022-12-21 12:38:58 +03:00
|
|
|
import django.contrib.auth
|
|
|
|
from django.contrib.auth import authenticate
|
|
|
|
from django.shortcuts import render, redirect
|
2022-12-11 17:20:42 +03:00
|
|
|
from django.http import HttpResponse
|
2022-12-21 12:38:58 +03:00
|
|
|
from django.views import View
|
|
|
|
|
|
|
|
from main.forms import UserCreationForm
|
2022-12-11 17:20:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
def index(request):
|
2022-12-11 18:02:38 +03:00
|
|
|
return render(request, 'main/index.html')
|
2022-12-11 17:20:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
def servers(request):
|
2022-12-11 18:02:38 +03:00
|
|
|
return render(request, 'main/servers.html')
|
2022-12-11 17:20:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
def mychat(request):
|
2022-12-11 18:02:38 +03:00
|
|
|
return render(request, 'main/mychat.html')
|
2022-12-11 17:20:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
def workout(request):
|
2022-12-11 18:02:38 +03:00
|
|
|
return render(request, 'main/workout.html')
|
2022-12-21 12:38:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
def login(request):
|
|
|
|
return render(request, 'registration/login.html')
|
|
|
|
|
|
|
|
|
|
|
|
def registration(request):
|
|
|
|
return render(request, 'registration/signin.html')
|
|
|
|
|
|
|
|
|
|
|
|
def logout(request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Register(View):
|
|
|
|
template_name = 'registration/signin.html'
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
context = {
|
|
|
|
'form': UserCreationForm()
|
|
|
|
}
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = UserCreationForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
|
|
|
username = form.cleaned_data.get('username')
|
|
|
|
password = form.cleaned_data.get('password1')
|
|
|
|
user = authenticate(username=username, password=password)
|
|
|
|
django.contrib.auth.login(request, user)
|
|
|
|
return redirect('home')
|
|
|
|
context = {
|
|
|
|
'form': form
|
|
|
|
}
|
|
|
|
return render(request, self.template_name, context)
|