mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Account history view
This commit is contained in:
@@ -2,9 +2,11 @@ from django.conf import settings
|
||||
from django.contrib.auth.models import (
|
||||
AbstractBaseUser, BaseUserManager, PermissionsMixin,
|
||||
)
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django_otp.models import Device
|
||||
|
||||
from pretix.base.i18n import language
|
||||
from pretix.helpers.urls import build_absolute_uri
|
||||
|
||||
@@ -152,6 +154,13 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
||||
except SendMailException:
|
||||
pass # Already logged
|
||||
|
||||
@property
|
||||
def all_logentries(self):
|
||||
from pretix.base.models import LogEntry
|
||||
|
||||
return LogEntry.objects.filter(content_type=ContentType.objects.get_for_model(User),
|
||||
object_id=self.pk)
|
||||
|
||||
|
||||
class U2FDevice(Device):
|
||||
json_data = models.TextField()
|
||||
|
||||
@@ -37,8 +37,7 @@ class LogEntry(models.Model):
|
||||
def display(self):
|
||||
from ..signals import logentry_display
|
||||
|
||||
if self.event:
|
||||
for receiver, response in logentry_display.send(self.event, logentry=self):
|
||||
if response:
|
||||
return response
|
||||
for receiver, response in logentry_display.send(self.event, logentry=self):
|
||||
if response:
|
||||
return response
|
||||
return self.action_type
|
||||
|
||||
@@ -62,9 +62,34 @@ def pretixcontrol_logentry_display(sender: Event, logentry: LogEntry, **kwargs):
|
||||
'pretix.event.order.contact.changed': _('The email address has been changed.'),
|
||||
'pretix.event.order.payment.changed': _('The payment method has been changed.'),
|
||||
'pretix.event.order.expire_warning_sent': _('An email has been sent with a warning that the order is about to expire.'),
|
||||
'pretix.user.settings.2fa.enabled': _('Two-factor authentication has been enabled.'),
|
||||
'pretix.user.settings.2fa.disabled': _('Two-factor authentication has been disabled.'),
|
||||
'pretix.user.settings.2fa.regenemergency': _('Your two-factor emergency codes have been regenerated.'),
|
||||
'pretix.control.auth.user.forgot_password.mail_sent': _('Password reset mail sent.'),
|
||||
'pretix.control.auth.user.forgot_password.recovered': _('The password has been reset.')
|
||||
|
||||
}
|
||||
if logentry.action_type in plains:
|
||||
return plains[logentry.action_type]
|
||||
|
||||
if logentry.action_type.startswith('pretix.event.order.changed'):
|
||||
return _display_order_changed(sender, logentry)
|
||||
|
||||
if logentry.action_type == 'pretix.user.settings.2fa.device.added':
|
||||
data = json.loads(logentry.data)
|
||||
return _('A new two-factor authentication device "{name}" has been added to your account.').format(
|
||||
name=data['name']
|
||||
)
|
||||
if logentry.action_type == 'pretix.user.settings.2fa.device.deleted':
|
||||
data = json.loads(logentry.data)
|
||||
return _('The two-factor authentication device "{name}" has been removed from your account.').format(
|
||||
name=data['name']
|
||||
)
|
||||
if logentry.action_type == 'pretix.user.settings.changed':
|
||||
data = json.loads(logentry.data)
|
||||
text = str(_('Your account settings have been changed.'))
|
||||
if 'email' in data:
|
||||
text = text + ' ' + str(_('Your email address has been changed to {email}.').format(email=data['email']))
|
||||
if 'new_pw' in data:
|
||||
text = text + ' ' + str(_('Your password has been changed.'))
|
||||
return text
|
||||
|
||||
15
src/pretix/control/templates/pretixcontrol/user/history.html
Normal file
15
src/pretix/control/templates/pretixcontrol/user/history.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends "pretixcontrol/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% block title %}{% trans "Account history" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{% trans "Account history" %}</h1>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">
|
||||
{% trans "Account history" %}
|
||||
</h3>
|
||||
</div>
|
||||
{% include "pretixcontrol/includes/logs.html" with obj=user %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -35,6 +35,15 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label" for="id_new_pw_repeat">{% trans "Account history" %}</label>
|
||||
<div class="col-md-9 static-form-row">
|
||||
<a href="{% url "control:user.settings.history" %}">
|
||||
<span class="fa fa-history"></span>
|
||||
{% trans "Show account history" %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
|
||||
@@ -15,6 +15,7 @@ urlpatterns = [
|
||||
url(r'^$', dashboards.user_index, name='index'),
|
||||
url(r'^settings$', user.UserSettings.as_view(), name='user.settings'),
|
||||
url(r'^settings/2fa/$', user.User2FAMainView.as_view(), name='user.settings.2fa'),
|
||||
url(r'^settings/history/$', user.UserHistoryView.as_view(), name='user.settings.history'),
|
||||
url(r'^settings/2fa/add$', user.User2FADeviceAddView.as_view(), name='user.settings.2fa.add'),
|
||||
url(r'^settings/2fa/enable', user.User2FAEnableView.as_view(), name='user.settings.2fa.enable'),
|
||||
url(r'^settings/2fa/disable', user.User2FADisableView.as_view(), name='user.settings.2fa.disable'),
|
||||
|
||||
@@ -6,6 +6,7 @@ from urllib.parse import quote
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.crypto import get_random_string
|
||||
@@ -18,7 +19,7 @@ from u2flib_server import u2f
|
||||
from u2flib_server.jsapi import DeviceRegistration
|
||||
|
||||
from pretix.base.forms.user import User2FADeviceAddForm, UserSettingsForm
|
||||
from pretix.base.models import U2FDevice, User
|
||||
from pretix.base.models import LogEntry, U2FDevice, User
|
||||
from pretix.control.views.auth import get_u2f_appid
|
||||
|
||||
REAL_DEVICE_TYPES = (TOTPDevice, U2FDevice)
|
||||
@@ -77,6 +78,15 @@ class UserSettings(UpdateView):
|
||||
return reverse('control:user.settings')
|
||||
|
||||
|
||||
class UserHistoryView(TemplateView):
|
||||
template_name = 'pretixcontrol/user/history.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
ctx['user'] = self.request.user
|
||||
return ctx
|
||||
|
||||
|
||||
class User2FAMainView(TemplateView):
|
||||
template_name = 'pretixcontrol/user/2fa_main.html'
|
||||
|
||||
@@ -138,7 +148,9 @@ class User2FADeviceDeleteView(TemplateView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.request.user.log_action('pretix.user.settings.2fa.device.deleted', user=self.request.user, data={
|
||||
'id': self.device.pk
|
||||
'id': self.device.pk,
|
||||
'name': self.device.name,
|
||||
'devicetype': self.kwargs['devicetype']
|
||||
})
|
||||
self.device.delete()
|
||||
msgs = [
|
||||
@@ -188,7 +200,8 @@ class User2FADeviceConfirmU2FView(TemplateView):
|
||||
self.device.save()
|
||||
self.request.user.log_action('pretix.user.settings.2fa.device.added', user=self.request.user, data={
|
||||
'id': self.device.pk,
|
||||
'devicetype': 'u2f'
|
||||
'devicetype': 'u2f',
|
||||
'name': self.device.name,
|
||||
})
|
||||
self.request.user.send_security_notice([
|
||||
_('A new two-factor authentication device has been added to your account.')
|
||||
@@ -230,6 +243,7 @@ class User2FADeviceConfirmTOTPView(TemplateView):
|
||||
self.device.save()
|
||||
self.request.user.log_action('pretix.user.settings.2fa.device.added', user=self.request.user, data={
|
||||
'id': self.device.pk,
|
||||
'name': self.device.name,
|
||||
'devicetype': 'totp'
|
||||
})
|
||||
self.request.user.send_security_notice([
|
||||
|
||||
Reference in New Issue
Block a user