Profile page + password changing

This commit is contained in:
Sebastian Lohff 2017-01-22 22:54:57 +01:00
parent 994cdfb234
commit d995feaad2
5 changed files with 56 additions and 5 deletions

4
TODO
View File

@ -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

View File

@ -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})

View File

@ -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,

View File

@ -66,7 +66,7 @@
{% endif %}
</ul>
{% if user.is_authenticated %}
<p class="navbar-text navbar-right"><kbd>{{ user.username }} @ {% if user.ref %}{{ user.ref }}{% else %}???{% endif %}</kbd></p>
<p class="navbar-text navbar-right"><a href="{% url "profile" %}"><kbd>{{ user.username }} @ {% if user.ref %}{{ user.ref }}{% else %}???{% endif %}</kbd></a></p>
{% endif %}
</div><!--/.nav-collapse -->
</div>

View File

@ -0,0 +1,36 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">User Info</div>
<div class="panel-body">
<p>
<dl class="dl-horizontal">
<dt>Username</dt>
<dd>{{ user }}</td>
<dt>Exchange</dt>
<dd>{{ user.ref|default:"Not registered" }}</td>
</dl>
</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Change Password</div>
<div class="panel-body">
<form method="POST" action="{% url "profile" %}">
{% csrf_token %}
{{ pwForm|crispy }}
<button type="submit" class="btn btn-primary" name="form" value="pwchange">Change Password</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}