register and change password in editor
This commit is contained in:
parent
155f09b966
commit
ec0c1d50b8
9 changed files with 134 additions and 39 deletions
17
src/c3nav/editor/templates/editor/change_password.html
Normal file
17
src/c3nav/editor/templates/editor/change_password.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% include 'editor/fragment_modal_close.html' %}
|
||||||
|
<h3>{% trans 'Change password' %}</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'editor.users.detail' pk=request.user.pk %}">« {% trans 'back' %}</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-primary btn-block">{% trans 'Change password' %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -12,4 +12,5 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button type="submit" class="btn btn-primary btn-block">{% trans 'Log in' %}</button>
|
<button type="submit" class="btn btn-primary btn-block">{% trans 'Log in' %}</button>
|
||||||
</div>
|
</div>
|
||||||
|
<a href="{% url 'editor.register' %}?{{ request.GET.urlencode }}">{% trans 'Create new account' %}</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
17
src/c3nav/editor/templates/editor/register.html
Normal file
17
src/c3nav/editor/templates/editor/register.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% include 'editor/fragment_modal_close.html' %}
|
||||||
|
<h3>{% trans 'Create new account' %}</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'editor.login' %}">« {% trans 'back' %}</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-primary btn-block">{% trans 'Create new account' %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -30,7 +30,9 @@
|
||||||
</p>
|
</p>
|
||||||
<form method="post" action="{{ request.path }}">
|
<form method="post" action="{{ request.path }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit" class="btn btn-xs btn-warning" name="direct_editing" value="0">{% trans 'Deactivate direct editing' %}</button>
|
<p>
|
||||||
|
<button type="submit" class="btn btn-xs btn-warning" name="direct_editing" value="0">{% trans 'Deactivate direct editing' %}</button>
|
||||||
|
</p>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
|
@ -40,9 +42,15 @@
|
||||||
{% if can_direct_edit %}
|
{% if can_direct_edit %}
|
||||||
<form method="post" action="{{ request.path }}">
|
<form method="post" action="{{ request.path }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit" class="btn btn-xs btn-warning" name="direct_editing" value="1">{% trans 'Activate direct editing' %}</button>
|
<p>
|
||||||
|
<button type="submit" class="btn btn-xs btn-warning" name="direct_editing" value="1">{% trans 'Activate direct editing' %}</button>
|
||||||
|
</p>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<p>
|
||||||
|
{% csrf_token %}
|
||||||
|
<a class="btn btn-xs btn-default" href="{% url 'editor.change_password' %}">{% trans 'Change password' %}</a>
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from c3nav.editor.views.account import change_password_view, login_view, logout_view, register_view
|
||||||
from c3nav.editor.views.changes import changeset_detail, changeset_edit
|
from c3nav.editor.views.changes import changeset_detail, changeset_edit
|
||||||
from c3nav.editor.views.edit import edit, graph_edit, level_detail, list_objects, main_index, space_detail
|
from c3nav.editor.views.edit import edit, graph_edit, level_detail, list_objects, main_index, space_detail
|
||||||
from c3nav.editor.views.login import login_view, logout_view
|
|
||||||
from c3nav.editor.views.users import user_detail
|
from c3nav.editor.views.users import user_detail
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ urlpatterns = [
|
||||||
url(r'^users/(?P<pk>[0-9]+)/$', user_detail, name='editor.users.detail'),
|
url(r'^users/(?P<pk>[0-9]+)/$', user_detail, name='editor.users.detail'),
|
||||||
url(r'^login$', login_view, name='editor.login'),
|
url(r'^login$', login_view, name='editor.login'),
|
||||||
url(r'^logout$', logout_view, name='editor.logout'),
|
url(r'^logout$', logout_view, name='editor.logout'),
|
||||||
|
url(r'^register$', register_view, name='editor.register'),
|
||||||
|
url(r'^change_password$', change_password_view, name='editor.change_password'),
|
||||||
]
|
]
|
||||||
urlpatterns.extend(add_editor_urls('Level', with_list=False, explicit_edit=True))
|
urlpatterns.extend(add_editor_urls('Level', with_list=False, explicit_edit=True))
|
||||||
urlpatterns.extend(add_editor_urls('LocationGroupCategory'))
|
urlpatterns.extend(add_editor_urls('LocationGroupCategory'))
|
||||||
|
|
84
src/c3nav/editor/views/account.py
Normal file
84
src/c3nav/editor/views/account.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth import login, logout
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm, UserCreationForm
|
||||||
|
from django.shortcuts import redirect, render
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from c3nav.editor.views.base import sidebar_view
|
||||||
|
|
||||||
|
|
||||||
|
@sidebar_view
|
||||||
|
def login_view(request):
|
||||||
|
redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.index')
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
return redirect(redirect_path)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = AuthenticationForm(request, data=request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
login(request, form.user_cache)
|
||||||
|
|
||||||
|
if request.changeset.pk is not None:
|
||||||
|
request.changeset.author = form.user_cache
|
||||||
|
request.changeset.save()
|
||||||
|
return redirect(redirect_path)
|
||||||
|
else:
|
||||||
|
form = AuthenticationForm(request)
|
||||||
|
|
||||||
|
return render(request, 'editor/login.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@sidebar_view
|
||||||
|
def logout_view(request):
|
||||||
|
redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.login')
|
||||||
|
logout(request)
|
||||||
|
return redirect(redirect_path)
|
||||||
|
|
||||||
|
|
||||||
|
@sidebar_view
|
||||||
|
def register_view(request):
|
||||||
|
redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.index')
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
return redirect(redirect_path)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = UserCreationForm(data=request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
user = form.save()
|
||||||
|
login(request, user)
|
||||||
|
|
||||||
|
if request.changeset.pk is not None:
|
||||||
|
request.changeset.author = user
|
||||||
|
request.changeset.save()
|
||||||
|
|
||||||
|
return redirect(redirect_path)
|
||||||
|
else:
|
||||||
|
form = UserCreationForm()
|
||||||
|
|
||||||
|
form.fields['username'].max_length = 20
|
||||||
|
for field in form.fields.values():
|
||||||
|
field.help_text = None
|
||||||
|
|
||||||
|
return render(request, 'editor/register.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@sidebar_view
|
||||||
|
@login_required(login_url='editor.login', redirect_field_name='r')
|
||||||
|
def change_password_view(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = PasswordChangeForm(user=request.user, data=request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
login(request, request.user)
|
||||||
|
messages.success(request, _('Password successfully changed.'))
|
||||||
|
return redirect('editor.users.detail', pk=request.user.pk)
|
||||||
|
|
||||||
|
else:
|
||||||
|
form = PasswordChangeForm(user=request.user)
|
||||||
|
|
||||||
|
for field in form.fields.values():
|
||||||
|
field.help_text = None
|
||||||
|
|
||||||
|
return render(request, 'editor/change_password.html', {'form': form})
|
|
@ -1,34 +0,0 @@
|
||||||
from django.contrib.auth import login, logout
|
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
|
||||||
from django.shortcuts import redirect, render
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from c3nav.editor.views.base import sidebar_view
|
|
||||||
|
|
||||||
|
|
||||||
@sidebar_view
|
|
||||||
def login_view(request):
|
|
||||||
redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.index')
|
|
||||||
if request.user.is_authenticated:
|
|
||||||
return redirect(redirect_path)
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = AuthenticationForm(request, data=request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
login(request, form.user_cache)
|
|
||||||
|
|
||||||
if request.changeset.pk is not None:
|
|
||||||
request.changeset.author = form.user_cache
|
|
||||||
request.changeset.save()
|
|
||||||
return redirect(redirect_path)
|
|
||||||
else:
|
|
||||||
form = AuthenticationForm(request)
|
|
||||||
|
|
||||||
return render(request, 'editor/login.html', {'form': form})
|
|
||||||
|
|
||||||
|
|
||||||
@sidebar_view
|
|
||||||
def logout_view(request):
|
|
||||||
redirect_path = request.GET['r'] if request.GET.get('r', '').startswith('/editor/') else reverse('editor.login')
|
|
||||||
logout(request)
|
|
||||||
return redirect(redirect_path)
|
|
|
@ -5,7 +5,7 @@
|
||||||
<main class="account">
|
<main class="account">
|
||||||
<h2>{% trans 'Change password' %}</h2>
|
<h2>{% trans 'Change password' %}</h2>
|
||||||
|
|
||||||
<p><a href="{% url 'site.account' %}">{% trans '« back' %}</a></p>
|
<p><a href="{% url 'site.account' %}">« {% trans 'back' %}</a></p>
|
||||||
|
|
||||||
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<main class="account">
|
<main class="account">
|
||||||
<h2>{% trans 'Create new account' %}</h2>
|
<h2>{% trans 'Create new account' %}</h2>
|
||||||
|
|
||||||
<p><a href="{% url 'site.login' %}">{% trans '« back' %}</a></p>
|
<p><a href="{% url 'site.login' %}">« {% trans 'back' %}</a></p>
|
||||||
|
|
||||||
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
<form method="post" action="{{ request.path_info }}?{{ request.GET.urlencode }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue