def register(request): from django.contrib.auth.models import User from website.models import Customer try: username = request.POST['username'] email = request.POST['email'] password = request.POST['password'] f = forms.userAjaxForm({'username': username, 'email': email, 'password': password}) if f.is_valid(): user = User.objects.create_user(username, email, password) user.save() customer = Customer( customer_id = user.id, customer_username=username, customer_first = "", customer_last = "", customer_email = email, customer_address = "", customer_telephone = "" ) customer.save() return HttpResponse('registered!') else: return HttpResponse('error!') except Exception as e: return HttpResponse(e)
def login(request): from django.contrib.auth import authenticate, login try: username = request.POST['username'] password = request.POST['password'] f = forms.userAjaxForm({'username': username, 'password': password}) if f.is_valid(): user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) request.session['userID'] = user.id return HttpResponse('login!') else: return HttpResponse('not active!') else: return HttpResponse('invalid login!') else: return HttpResponse('error!') except Exception as e: return HttpResponse(e)