core: add user settings and user delete

This commit is contained in:
Jens Langhammer 2018-12-10 16:58:35 +01:00
parent 276c6fb297
commit 71f41e655f
12 changed files with 99 additions and 32 deletions

View File

@ -9,7 +9,7 @@
{% endblock %}
<div class="">
<form action="" method="post" class="form-horizontal">
{% include 'blocks/form.html' with form=form %}
{% include 'partials/form.html' with form=form %}
<a class="btn btn-default" href="{% back %}">{% trans "Cancel" %}</a>
<input type="submit" class="btn btn-primary" value="{% trans 'Create' %}" />
</form>

View File

@ -0,0 +1,14 @@
"""passbook core user forms"""
from django import forms
from passbook.core.models import User
class UserDetailForm(forms.ModelForm):
"""Update User Details"""
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email']

View File

@ -7,6 +7,5 @@ from django.core.signals import Signal
# from passbook.core.models import Invitation, User
user_signed_up = Signal(providing_args=['request', 'user'])
# TODO: Send this signal in admin interface
invitation_created = Signal(providing_args=['request', 'invitation'])
invitation_used = Signal(providing_args=['request', 'invitation', 'user'])

View File

@ -38,13 +38,7 @@
</button>
<ul class="dropdown-menu">
<li>
<a href="#0">Link</a>
</li>
<li>
<a href="#0">Another link</a>
</li>
<li>
<a href="#0">Something else here</a>
<a href="{% url 'passbook_core:user-settings' %}">{% trans 'User Settings' %}</a>
</li>
<li class="divider"></li>
<li>
@ -55,7 +49,7 @@
</ul>
{% is_active_app 'passbook_admin' as is_admin %}
<ul class="nav navbar-nav navbar-primary {% if is_admin == 'active' %}persistent-secondary{% endif %}">
<li class="{% is_active_app 'passbook_core' %}">
<li class="{% is_active 'passbook_core:overview' %}">
<a href="{% url 'passbook_core:overview' %}">{% trans 'Overview' %}</a>
</li>
<li class="{% is_active_app 'passbook_admin' %}">

View File

@ -0,0 +1,24 @@
{% extends "overview/base.html" %}
{% load i18n %}
{% load is_active %}
{% block content %}
<div class="container">
<div class="col-md-3 ">
<div class="nav-category">
<h2>{% trans 'User Profile'%}</h2>
<ul class="nav nav-pills nav-stacked">
<li class="{% is_active 'passbook_core:user-settings' %}"><a href="{% url 'passbook_core:user-settings' %}"><i class="fa fa-desktop"></i>{% trans 'Details' %}</a></li>
<li><a href="#"><i class="fa fa-cog"></i>System Services</a></li>
<li><a href="#"><i class="fa fa-file-text-o"></i>Journal</a></li>
<li><a href="#"><i class="fa fa-cloud"></i>Storage</a></li>
</ul>
</div>
</div>
<div class="col-md-9">
{% block page %}
{% endblock %}
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "user/base.html" %}
{% load i18n %}
{% block page %}
<h1>{% trans 'Update details' %}</h1>
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
{% include 'partials/form.html' %}
<input class="btn btn-primary" type="submit" value="{% trans 'Update' %}">
<a class="btn btn-danger" href="{% url 'passbook_core:user-delete' %}?back={{ request.get_full_path }}">{% trans 'Delete user' %}</a>
</form>
{% endblock %}

View File

@ -6,7 +6,7 @@ from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
from passbook.core.views import authentication, overview
from passbook.core.views import authentication, overview, user
from passbook.lib.utils.reflection import get_apps
LOGGER = getLogger(__name__)
@ -14,9 +14,14 @@ admin.autodiscover()
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
core_urls = [
# Authentication views
path('auth/login/', authentication.LoginView.as_view(), name='auth-login'),
path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'),
path('auth/sign_up/', authentication.SignUpView.as_view(), name='auth-sign-up'),
# User views
path('user/', user.UserSettingsView.as_view(), name='user-settings'),
path('user/delete/', user.UserDeleteView.as_view(), name='user-delete'),
# Overview
path('', overview.OverviewView.as_view(), name='overview'),
]

View File

@ -211,20 +211,8 @@ class SignUpView(UserPassesTestMixin, FormView):
sender=SignUpView,
user=new_user,
request=request)
# try:
# TODO: Create signal for signup
# on_user_sign_up.send(
# sender=None,
# user=new_user,
# request=request,
# password=data.get('password'),
# needs_confirmation=needs_confirmation)
# TODO: Implement Verification, via email or others
# if needs_confirmation:
# Create Account Confirmation UUID
# AccountConfirmation.objects.create(user=new_user)
# except SignalException as exception:
# LOGGER.warning("Failed to sign up user %s", exception, exc_info=exception)
# new_user.delete()
# raise
return new_user

View File

@ -0,0 +1,30 @@
"""passbook core user views"""
from django.contrib import messages
from django.contrib.auth import logout
from django.urls import reverse
from django.utils.translation import gettext as _
from django.views.generic import DeleteView, UpdateView
from passbook.core.forms.user import UserDetailForm
class UserSettingsView(UpdateView):
"""Update User settings"""
template_name = 'user/settings.html'
form_class = UserDetailForm
def get_object(self):
return self.request.user
class UserDeleteView(DeleteView):
"""Delete user account"""
template_name = 'generic/delete.html'
def get_object(self):
return self.request.user
def get_success_url(self):
messages.success(self.request, _('Successfully deleted user.'))
logout(self.request)
return reverse('passbook_core:auth-login')

View File

@ -15,13 +15,13 @@
<form role="form" method="POST">
<div class="card-block">
<h3><clr-icon shape="cog" size="32"></clr-icon>{% trans 'General settings' %}</h3>
{% include 'blocks/form.html' with form=general %}
{% include 'partials/form.html' with form=general %}
<h3><clr-icon shape="connect" size="32"></clr-icon>{% trans 'Connection settings' %}</h3>
{% include 'blocks/form.html' with form=connection %}
{% include 'partials/form.html' with form=connection %}
<h3><clr-icon shape="certificate" size="32"></clr-icon>{% trans 'Authentication backend ' %}</h3>
{% include 'blocks/form.html' with form=authentication %}
{% include 'partials/form.html' with form=authentication %}
<h3><clr-icon shape="users" size="32"></clr-icon>{% trans 'Create users settings' %}</h3>
{% include 'blocks/form.html' with form=create_users %}
{% include 'partials/form.html' with form=create_users %}
</div>
<div class="card-footer">
<button type="submit" value="general" class="btn btn-sm btn-primary">{% trans 'Update' %}</button>