Added account page and change password form

master
Laurent 6 years ago
parent 11d75e2992
commit 216ea1a82c
  1. BIN
      db.sqlite3
  2. BIN
      news/__pycache__/urls.cpython-37.pyc
  3. BIN
      news/__pycache__/views.cpython-37.pyc
  4. 2
      news/templates/base.html
  5. 12
      news/templates/news/index.html
  6. 27
      news/templates/news/user/account.html
  7. 15
      news/templates/news/user/change_password.html
  8. 6
      news/templates/news/user/register.html
  9. 6
      news/templates/news/user/signin.html
  10. 3
      news/urls.py
  11. 23
      news/views.py

Binary file not shown.

@ -26,6 +26,8 @@
<p> <p>
<br/> <br/>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<a href="{% url 'news:account' %}">[ {{ user.username }} ]</a>
<br/>
<a href="{% url 'news:submission' %}">Submit</a> <a href="{% url 'news:submission' %}">Submit</a>
<br/> <br/>
<a href="{% url 'news:logout_view' %}">Log out</a> <a href="{% url 'news:logout_view' %}">Log out</a>

@ -99,6 +99,18 @@
{% endfor %} {% endfor %}
<!-- Pagination --> <!-- Pagination -->
<!-- <ul class="pagination" role="navigation" aria-label="Pagination">
<li class="disabled">Previous <span class="show-for-sr">page</span></li>
<li class="current"><span class="show-for-sr">You're on page</span> 1</li>
<li><a href="#0" aria-label="Page 2">2</a></li>
<li><a href="#0" aria-label="Page 3">3</a></li>
<li><a href="#0" aria-label="Page 4">4</a></li>
<li class="ellipsis" aria-hidden="true"></li>
<li><a href="#0" aria-label="Page 12">12</a></li>
<li><a href="#0" aria-label="Page 13">13</a></li>
<li><a href="#0" aria-label="Next page">Next <span class="show-for-sr">page</span></a></li>
</ul> -->
<div class="pagination"> <div class="pagination">
<span class="step-links"> <span class="step-links">
{% if latest_post_list.has_previous %} {% if latest_post_list.has_previous %}

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block title %}
Account
{% endblock %}
{% block content %}
<div class="login">
{% if messages %}
<p>
{% for message in messages %}
<span class="primary label">{{ message }}</span>
{% endfor %}
</p>
{% endif %}
<h1>Account</h1>
<ul>
<li><a href="{% url 'news:password_change' %}">Change password</a></li>
</ul>
</div>
{% endblock %}

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block title %}
Change password
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit">Save changes</button>
</form>
{% endblock %}

@ -9,11 +9,11 @@
<div class="login"> <div class="login">
{% if messages %} {% if messages %}
<ul> <p>
{% for message in messages %} {% for message in messages %}
<li>{{ message }}</li> <span class="primary label">{{ message }}</span>
{% endfor %} {% endfor %}
</ul> </p>
{% endif %} {% endif %}
<h1>Create account</h1> <h1>Create account</h1>

@ -9,11 +9,11 @@
<div class="login"> <div class="login">
{% if messages %} {% if messages %}
<ul> <p>
{% for message in messages %} {% for message in messages %}
<li>{{ message }}</li> <span class="primary label">{{ message }}</span>
{% endfor %} {% endfor %}
</ul> </p>
{% endif %} {% endif %}
<h1>Sign in</h1> <h1>Sign in</h1>

@ -7,11 +7,12 @@ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('<int:post_id>', views.post, name='post'), path('<int:post_id>', views.post, name='post'),
path('submission', views.submission, name='submission'), path('submission', views.submission, name='submission'),
# path('submit', views.submit, name='submit'),
path('<int:post_id>/comment', views.comment, name='comment'), path('<int:post_id>/comment', views.comment, name='comment'),
path('submitted', views.submitted, name='submitted'), path('submitted', views.submitted, name='submitted'),
path('account', views.account, name='account'),
path('signin', views.signin, name='signin'), path('signin', views.signin, name='signin'),
path('logout', views.logout_view, name='logout_view'), path('logout', views.logout_view, name='logout_view'),
path('password-change', views.password_change, name='password_change'),
re_path(r'^register/$', views.register, name='register'), re_path(r'^register/$', views.register, name='register'),
] ]

@ -6,8 +6,9 @@ from django.core.paginator import Paginator
from django.conf import settings from django.conf import settings
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import authenticate, login, logout from django.contrib.auth import authenticate, login, logout, update_session_auth_hash
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm
from .models import Post, Comment from .models import Post, Comment
from .forms import PostForm, CustomUserCreationForm, SigninForm from .forms import PostForm, CustomUserCreationForm, SigninForm
from datetime import datetime from datetime import datetime
@ -47,10 +48,30 @@ def signin(request):
f = SigninForm() f = SigninForm()
return render(request, 'news/user/signin.html', {'form': f}) return render(request, 'news/user/signin.html', {'form': f})
@login_required
def logout_view(request): def logout_view(request):
logout(request) logout(request)
return HttpResponseRedirect(reverse('news:index')) return HttpResponseRedirect(reverse('news:index'))
@login_required
def account(request):
return render(request, 'news/user/account.html', {})
@login_required
def password_change(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important!
messages.success(request, 'Your password was successfully updated!')
return render(request, 'news/user/account.html', {})
else:
messages.error(request, 'Please correct the error below.')
else:
form = PasswordChangeForm(request.user)
return render(request, 'news/user/change_password.html', {'form': form})
#Post #Post
def index(request): def index(request):
latest_post_list = Post.objects.filter(state=1).order_by('-date') latest_post_list = Post.objects.filter(state=1).order_by('-date')

Loading…
Cancel
Save