Commit f76bd1a8 authored by dorothee.kueppers's avatar dorothee.kueppers
Browse files

all-auth added

parent 24a82c55
......@@ -34,12 +34,12 @@ DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django_crontab',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
......@@ -48,6 +48,10 @@ INSTALLED_APPS = [
'todo',
'bootstrap4',
'recurrence',
'allauth',
'allauth.account',
'allauth.socialaccount',
]
MIDDLEWARE = [
......@@ -67,8 +71,7 @@ ROOT_URLCONF = 'oos_2020_todo.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -81,8 +84,17 @@ TEMPLATES = [
},
]
WSGI_APPLICATION = 'oos_2020_todo.wsgi.application'
SITE_ID = 1
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
]
WSGI_APPLICATION = 'oos_2020_todo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
......@@ -97,7 +109,6 @@ WSGI_APPLICATION = 'oos_2020_todo.wsgi.application'
DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......@@ -116,7 +127,6 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
......@@ -132,7 +142,6 @@ USE_TZ = True
RECURRENCE_USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
......@@ -144,14 +153,13 @@ CRONJOBS = [
('0 8 * * *', 'todo.cron.email_todays_todos')
]
EMAIL_HOST = 'mail.gmx.net'
EMAIL_PORT: 587
EMAIL_HOST_USER: 'feierabend-todo@gmx.de'
EMAIL_HOST_PASSWORD: 'oos_2020_todo'
EMAIL_USE_TLS = True
# EMAIL_HOST = 'mail.gmx.net'
# EMAIL_PORT: 587
# EMAIL_HOST_USER: 'feierabend-todo@gmx.de'
# EMAIL_HOST_PASSWORD: 'oos_2020_todo'
# EMAIL_USE_TLS = True
# Activate Django-Heroku.
django_heroku.settings(locals())
del DATABASES['default']['OPTIONS']['sslmode']
\ No newline at end of file
del DATABASES['default']['OPTIONS']['sslmode']
......@@ -16,12 +16,12 @@ Including another URLconf
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.views.i18n import JavaScriptCatalog
from django.conf import settings
from todo.views import get_landing_page, get_selection_page, todo_details, get_impressum, get_show_todo, \
get_archiv, get_selection_id, delete_todo, get_register, get_login
get_archiv, get_selection_id, delete_todo, redirect_profile
urlpatterns = [
path('admin/', admin.site.urls),
......@@ -36,8 +36,11 @@ urlpatterns = [
path('impressum/', get_impressum, name='impressum'),
path('todo/show/', get_show_todo, name='show_todo'),
path('todo/archiv/', get_archiv, name='archiv'),
path('todo/register/', get_register, name="register"),
path('todo/login/', get_login, name="login"),
# path('accounts/register/', get_register, name="register"),
# path('accounts/login/', get_login, name="login"),
# path('accounts/logout/', get_login, name="login"),
path('accounts/', include('allauth.urls')),
path('accounts/profile/', redirect_profile, name="redirect_profile"),
]
if settings.DEBUG:
......
......@@ -51,13 +51,9 @@
</div>
<!-- Navbar auf rechter Seite/Log In und Register Seite-->
<div class="navbar-nav">
<a class="nav-item nav-link active" href="{% url 'login' %}">Login</a>
<a class="nav-item nav-link active" href="accounts/logout">Logout</a>
</div>
<div class="navbar-nav">
<a class="nav-item nav-link active" href="{% url 'register' %}">Register</a>
</div>
</nav>
{% endblock %}
......
import logging
from django.contrib import messages
from django.core.mail import send_mail
from django.db.models import Max, Model
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.utils import timezone
from django.contrib.auth.decorators import login_required
from oos_2020_todo import settings
from todo.forms import *
from todo.models import *
logger = logging.getLogger('views')
def register_page(request):
if request.user.is_authenticated:
return redirect('landing_page')
else:
form = CreateUserForm()
if request.method == 'POST':
form = CreateUserForm(request.POST)
if form.is_valid():
form.save()
return redirect('login')
context = {'form': form}
return render(request, 'todo/register.html', context)
def login_page(request):
if request.user.is_authenticated:
return redirect('login')
else:
context = {}
return render(request, 'todo/login.html', context)
@login_required(login_url='login')
# def register_page(request):
# if request.user.is_authenticated:
# return redirect('landing_page')
# else:
# form = CreateUserForm()
# if request.method == 'POST':
# form = CreateUserForm(request.POST)
# if form.is_valid():
# form.save()
# return redirect('login')
#
# context = {'form': form}
# return render(request, 'todo/register.html', context)
#
#
# def login_page(request):
# if request.user.is_authenticated:
# return redirect('login')
# else:
# context = {}
# return render(request, 'todo/login.html', context)
@login_required()
def get_landing_page(request):
try:
selection = Selection.objects.filter(active=True).latest('endtime')
......@@ -55,7 +50,8 @@ def get_landing_page(request):
return render(request, 'todo/landing_page.html', content)
@login_required(login_url='login')
@login_required()
def todo_details(request, pk=None):
if pk:
todo = Todo.objects.get(pk=pk)
......@@ -77,7 +73,8 @@ def todo_details(request, pk=None):
return render(request, 'todo/add_todo.html', {'page_title': 'Lege eine neue Aufgabe an! ',
'form': form})
@login_required(login_url='login')
@login_required()
def delete_todo(request, pk=None, source='show_todo', s_id=None):
if pk:
Todo.objects.get(pk=pk).delete()
......@@ -86,7 +83,8 @@ def delete_todo(request, pk=None, source='show_todo', s_id=None):
else:
return HttpResponseRedirect(reverse_lazy(source))
@login_required(login_url='login')
@login_required()
def get_selection_page(request):
selection = Selection()
......@@ -125,7 +123,8 @@ def get_selection_page(request):
}
return render(request, 'todo/selection_page.html', content)
@login_required(login_url='login')
@login_required()
def get_selection_id(request, pk=None):
if request.method == 'POST':
form = CheckedTodosForm(request.POST)
......@@ -161,7 +160,7 @@ def get_selection_id(request, pk=None):
}
return render(request, 'todo/show_selection.html', content)
@login_required(login_url='login')
def sort_todos(todos_late, todos_someday, todos_soon, todos_today, select_id=None):
if select_id is None:
todos_with_recurrence = Todo.objects.filter(complete=False).exclude(recurrences__exact='')
......@@ -196,7 +195,8 @@ def get_impressum(request):
content = {'page_title': 'Impressum'}
return render(request, 'todo/impressum.html', content)
@login_required(login_url='login')
@login_required()
def get_show_todo(request):
if request.method == 'POST':
form = CheckedTodosForm(request.POST)
......@@ -232,19 +232,15 @@ def get_show_todo(request):
}
return render(request, 'todo/show_todo.html', content)
@login_required(login_url='login')
@login_required()
def get_archiv(request):
todos = Todo.objects.filter(complete=True)
content = {'page_title': 'Archiv',
'todos_complete' : todos}
'todos_complete': todos}
return render(request, 'todo/archiv.html', content)
def get_login(request):
content = {'page_title': 'Log In'}
return render(request, 'todo/login.html', content)
login_required()
def get_register(request):
content = {'page_title': 'Register'}
return render(request, 'todo/register.html', content)
@login_required()
def redirect_profile(request):
return HttpResponseRedirect(reverse_lazy('landing_page'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment