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. 14
      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>
<br/>
{% if user.is_authenticated %}
<a href="{% url 'news:account' %}">[ {{ user.username }} ]</a>
<br/>
<a href="{% url 'news:submission' %}">Submit</a>
<br/>
<a href="{% url 'news:logout_view' %}">Log out</a>

@ -79,7 +79,7 @@
</div>
</div>
<div class="info">
{{ post.date }} - {{ post.author.username }} - <a href="{% url 'news:post' post.id %}">{% if post.comment_set.count > 0 %}{{ post.comment_set.count }} comments{% else %}write comment{% endif %}</a>
</div>
@ -99,6 +99,18 @@
{% endfor %}
<!-- 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">
<span class="step-links">
{% 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">
{% if messages %}
<ul>
<p>
{% for message in messages %}
<li>{{ message }}</li>
<span class="primary label">{{ message }}</span>
{% endfor %}
</ul>
</p>
{% endif %}
<h1>Create account</h1>

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

@ -7,11 +7,12 @@ urlpatterns = [
path('', views.index, name='index'),
path('<int:post_id>', views.post, name='post'),
path('submission', views.submission, name='submission'),
# path('submit', views.submit, name='submit'),
path('<int:post_id>/comment', views.comment, name='comment'),
path('submitted', views.submitted, name='submitted'),
path('account', views.account, name='account'),
path('signin', views.signin, name='signin'),
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'),
]

@ -6,8 +6,9 @@ from django.core.paginator import Paginator
from django.conf import settings
from django.contrib.auth.forms import UserCreationForm
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.forms import PasswordChangeForm
from .models import Post, Comment
from .forms import PostForm, CustomUserCreationForm, SigninForm
from datetime import datetime
@ -47,10 +48,30 @@ def signin(request):
f = SigninForm()
return render(request, 'news/user/signin.html', {'form': f})
@login_required
def logout_view(request):
logout(request)
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
def index(request):
latest_post_list = Post.objects.filter(state=1).order_by('-date')

Loading…
Cancel
Save