2016-03-07 16:49:02 +00:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.views.generic import View
|
2016-03-03 21:55:23 +00:00
|
|
|
|
2016-03-07 16:49:02 +00:00
|
|
|
from .models import CustomUser
|
|
|
|
from .forms import LoginForm, RegisterForm
|
2016-03-07 18:25:01 +00:00
|
|
|
from django.contrib.auth import authenticate,login
|
2016-03-07 16:49:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def validate_email(request, validate_slug):
|
|
|
|
validated = User.validate_url(validate_slug)
|
|
|
|
if validated:
|
|
|
|
return render(request,'templates/validated.html')
|
|
|
|
else:
|
|
|
|
return render(request,'templates/error.html')
|
|
|
|
|
|
|
|
|
|
|
|
class LoginRegistrationView(View):
|
|
|
|
def get(self, request):
|
|
|
|
login_form = LoginForm()
|
|
|
|
register_form = RegisterForm()
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
return redirect("membership")
|
|
|
|
else:
|
|
|
|
return render(request, 'templates/login.html', {'login_form': login_form, 'register_form': register_form})
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
email = request.POST.get('email')
|
|
|
|
password = request.POST.get('password')
|
|
|
|
name = request.POST.get('name')
|
|
|
|
if name and email and password:
|
|
|
|
user = CustomUser.register(name, password,email)
|
|
|
|
if user:
|
|
|
|
return render(request, 'templates/success.html')
|
|
|
|
else:
|
|
|
|
return render(request, 'templates/error.html')
|
|
|
|
|
|
|
|
elif email and password and not name:
|
2016-03-07 18:25:01 +00:00
|
|
|
user = authenticate(email=email, password=password)
|
2016-03-07 16:49:02 +00:00
|
|
|
if user:
|
2016-03-07 18:25:01 +00:00
|
|
|
login(request,user)
|
2016-03-07 16:49:02 +00:00
|
|
|
return redirect('membership')
|
|
|
|
else:
|
|
|
|
return render(request, 'templates/login', {'msg': 'Wrong username or password'})
|
|
|
|
|
|
|
|
class MembershipView(View):
|
|
|
|
def get(self,request):
|
|
|
|
return render(request,'templates/membership.html')
|