From d995feaad2d50df470840f5e27b46956e180a6e5 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 22 Jan 2017 22:54:57 +0100 Subject: [PATCH] Profile page + password changing --- TODO | 4 ++-- contest/views.py | 16 ++++++++++++- cqtu/urls.py | 3 ++- templates/base.html | 2 +- templates/registration/profile.html | 36 +++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 templates/registration/profile.html diff --git a/TODO b/TODO index 5f26982..ea3a292 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ - bastla will die passwort regeln einfacher haben - beim qso log kann noch vorne die uhrzeit dran - - ggf passwort ändern - bastla will anderen regex - - dj7xj: mit space ins nächste feld springen - dj7xj: EXC in logzeile fest anzeigen (Partially) Done @@ -17,6 +15,8 @@ - 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! + - dj7xj: mit space ins nächste feld springen + - ggf passwort ändern 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 9860db7..a9f5b5d 100644 --- a/contest/views.py +++ b/contest/views.py @@ -3,7 +3,7 @@ from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.contrib.admin.views.decorators import staff_member_required from django.db.models import Q -from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm from django.http import HttpResponseRedirect from django.contrib import messages from django.urls import reverse @@ -156,3 +156,17 @@ def register(request): form = CustomUserCreationForm() return render(request, 'registration/register.html', {"form": form}) + +@login_required +def profile(request): + pwForm = None + if request.method == 'POST': + pwForm = PasswordChangeForm(user=request.user, data=request.POST) + if pwForm.is_valid(): + pwForm.save() + auth_login(request, pwForm.user) + messages.success(request, "Password changed") + else: + pwForm = PasswordChangeForm(user=request.user) + + return render(request, 'registration/profile.html', {"pwForm": pwForm}) diff --git a/cqtu/urls.py b/cqtu/urls.py index 195f17e..48bec36 100644 --- a/cqtu/urls.py +++ b/cqtu/urls.py @@ -21,7 +21,7 @@ from django.contrib.auth import views as auth_views #from django.contrib.auth.forms import UserCreationForm #from contest.forms import CustomUserCreationForm -from contest.views import index, register +from contest.views import index, register, profile @@ -33,6 +33,7 @@ urlpatterns = [ 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'^profile/$', profile, name='profile'), #url(r'^register/$', CreateView.as_view( # template_name='registration/register.html', # form_class=CustomUserCreationForm, diff --git a/templates/base.html b/templates/base.html index e95e765..ee49449 100644 --- a/templates/base.html +++ b/templates/base.html @@ -66,7 +66,7 @@ {% endif %} {% if user.is_authenticated %} - + {% endif %} diff --git a/templates/registration/profile.html b/templates/registration/profile.html new file mode 100644 index 0000000..b4efdf4 --- /dev/null +++ b/templates/registration/profile.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% load crispy_forms_tags %} + +{% block content %} +
+
+
+
User Info
+
+

+

+
Username
+
{{ user }} +
Exchange
+
{{ user.ref|default:"Not registered" }} +
+

+
+
+
+
+
+
Change Password
+
+
+ {% csrf_token %} + {{ pwForm|crispy }} + +
+
+
+
+
+{% endblock %} +