From ad8eeeb95554b9cd97497445d3ef6515d02f7148 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sat, 21 Jan 2017 03:16:27 +0100 Subject: [PATCH] Direct login after registration --- TODO | 3 +-- contest/views.py | 17 +++++++++++++++-- cqtu/urls.py | 18 +++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 1c15215..8d8da02 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ - - after registration direct login! - - bastla will die passwort regeln einfacher haben - beim qso log kann noch vorne die uhrzeit dran @@ -14,6 +12,7 @@ - forms müssen crispy! oderso. sollen schöner - call dupe check mit tastypie based on call+band - qsoform muss den report richtig parsen, gucken ob es [0-5][0-9] ist (blöden validator adden) + - after registration direct login! Glaube nich, dass ich das mache - call dupe validation könnte ins model wandern diff --git a/contest/views.py b/contest/views.py index bba8ccc..9860db7 100644 --- a/contest/views.py +++ b/contest/views.py @@ -7,11 +7,12 @@ from django.contrib.auth.forms import AuthenticationForm from django.http import HttpResponseRedirect from django.contrib import messages from django.urls import reverse +from django.contrib.auth import login as auth_login import datetime from .models import User, Contest, Frequency, Reference, QSO -from .forms import UpdateRefForm, QSOForm, QSOFormWithTime +from .forms import UpdateRefForm, QSOForm, QSOFormWithTime, CustomUserCreationForm def index(request): if request.user.is_authenticated(): @@ -142,4 +143,16 @@ def overview(request): return render(request, 'contest/overview.html', {'contest': c, 'qrgs': qrgs}) def register(request): - return render(request, 'registration/register.html', {}) + form = None + if request.method == 'POST': + form = CustomUserCreationForm(data=request.POST) + if form.is_valid(): + form.instance.save() + auth_login(request, form.instance) + messages.info(request, "Registration as user %s successfull!" % form.instance.username) + + return HttpResponseRedirect(reverse("contest:index")) + else: + form = CustomUserCreationForm() + + return render(request, 'registration/register.html', {"form": form}) diff --git a/cqtu/urls.py b/cqtu/urls.py index f48a098..195f17e 100644 --- a/cqtu/urls.py +++ b/cqtu/urls.py @@ -17,11 +17,11 @@ from django.conf.urls import url, include from django.contrib import admin from django.contrib.auth import views as auth_views -from django.views.generic.edit import CreateView +#from django.views.generic.edit import CreateView #from django.contrib.auth.forms import UserCreationForm -from contest.forms import CustomUserCreationForm -from contest.views import index +#from contest.forms import CustomUserCreationForm +from contest.views import index, register @@ -32,10 +32,10 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^login/$', auth_views.login, name='login'), url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'), - #url(r'^register/$', register, name='register'), - url(r'^register/$', CreateView.as_view( - template_name='registration/register.html', - form_class=CustomUserCreationForm, - success_url='/', - ), name='register'), + url(r'^register/$', register, name='register'), + #url(r'^register/$', CreateView.as_view( + # template_name='registration/register.html', + # form_class=CustomUserCreationForm, + # success_url='/', + #), name='register'), ]