2018-12-14 13:24:04 +00:00
|
|
|
"""passbook User administration"""
|
2019-02-25 19:46:23 +00:00
|
|
|
from django.contrib import messages
|
2018-12-14 13:24:04 +00:00
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
2019-02-25 19:46:23 +00:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
|
|
from django.urls import reverse, reverse_lazy
|
2018-12-14 13:24:04 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2019-02-25 19:46:23 +00:00
|
|
|
from django.views import View
|
2018-12-14 13:33:15 +00:00
|
|
|
from django.views.generic import DeleteView, ListView, UpdateView
|
2018-12-14 13:24:04 +00:00
|
|
|
|
|
|
|
from passbook.admin.mixins import AdminRequiredMixin
|
2019-02-16 09:59:23 +00:00
|
|
|
from passbook.core.forms.users import UserDetailForm
|
2019-02-25 19:46:23 +00:00
|
|
|
from passbook.core.models import Nonce, User
|
2018-12-14 13:24:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserListView(AdminRequiredMixin, ListView):
|
|
|
|
"""Show list of all users"""
|
|
|
|
|
|
|
|
model = User
|
|
|
|
template_name = 'administration/user/list.html'
|
|
|
|
|
|
|
|
|
|
|
|
class UserUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView):
|
|
|
|
"""Update user"""
|
|
|
|
|
|
|
|
model = User
|
|
|
|
form_class = UserDetailForm
|
|
|
|
|
|
|
|
template_name = 'generic/update.html'
|
|
|
|
success_url = reverse_lazy('passbook_admin:users')
|
|
|
|
success_message = _('Successfully updated User')
|
|
|
|
|
|
|
|
|
|
|
|
class UserDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView):
|
|
|
|
"""Delete user"""
|
|
|
|
|
|
|
|
model = User
|
|
|
|
|
|
|
|
success_url = reverse_lazy('passbook_admin:users')
|
|
|
|
success_message = _('Successfully updated User')
|
2019-02-25 19:46:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserPasswordResetView(AdminRequiredMixin, View):
|
|
|
|
"""Get Password reset link for user"""
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def get(self, request, pk):
|
|
|
|
"""Create nonce for user and return link"""
|
|
|
|
user = get_object_or_404(User, pk=pk)
|
|
|
|
nonce = Nonce.objects.create(user=user)
|
|
|
|
link = request.build_absolute_uri(reverse(
|
|
|
|
'passbook_core:auth-password-reset', kwargs={'nonce': nonce.uuid}))
|
|
|
|
messages.success(request, _('Password reset link: <pre>%(link)s</pre>' % {'link': link}))
|
|
|
|
return redirect('passbook_admin:users')
|