diff --git a/main/templates/login.html b/main/templates/login.html index 4bd4e6f..7644581 100644 --- a/main/templates/login.html +++ b/main/templates/login.html @@ -1,149 +1,72 @@ +{% extends 'base.html' %} {% load static %} - - - +{% block head %} - +{% endblock %} - -
-
- - -
- ONTARIO ASSOCIATION OF -
- CHILD PROTECTION LAWYERS +{% block body %} +
-
- - - +{% endblock %} diff --git a/main/views.py b/main/views.py index e5f8877..17c511d 100644 --- a/main/views.py +++ b/main/views.py @@ -1,9 +1,9 @@ -import json - -from django.shortcuts import HttpResponse, render, redirect +from django.shortcuts import render, redirect from django.contrib import auth +from django.contrib.auth.models import User from charter_members.models import Attorney +from newsletters.models import Subscriber def index(request): @@ -13,13 +13,30 @@ def index(request): def login(request): if request.method == 'POST': - user = auth.authenticate(request) - if user: - return HttpResponse(json.dumps({'status': True})) - else: - return HttpResponse(json.dumps({'status': False})) + if request.POST.get('request') == 'login': + user = auth.authenticate(request, username=request.POST.get('username'), password=request.POST.get('password')) + if user: + auth.login(request, user) + return redirect('/') + else: + return render(request, 'login.html', {'navbar': False, 'footer': False, 'failed': True}) + elif request.POST.get('request') == 'register': + user = User.objects.create_user(request.POST.get('username'), + email=request.POST.get('email'), + password=request.POST.get('password')) + user.save() + # TODO: Send confirmation email + if request.POST.get('newsletter'): + Subscriber.objects.create(email=request.POST.get('email')) + # TODO: If Case law access was requested, send an email out to staff + auth.login(request, user) + return redirect('/') + + elif request.POST.get('request') == 'reset': + # TODO: Reset password and send email + pass else: - return render(request, 'login.html') + return render(request, 'login.html', {'navbar': False, 'footer': False}) def logout(request): diff --git a/templates/base.html b/templates/base.html index e227c6d..f3e38ab 100644 --- a/templates/base.html +++ b/templates/base.html @@ -24,77 +24,82 @@ {% csrf_token %} - - +{% endif %} + {% block body %} {% endblock %} - -
-
-

© 2017 Ontario Association of Child Protection Lawyers.

-
-
+{% if footer|default_if_none:True %} + + +{% endif %}