diff --git a/src/pretix/base/forms/user.py b/src/pretix/base/forms/user.py index c5d56dda6..9dcf101fc 100644 --- a/src/pretix/base/forms/user.py +++ b/src/pretix/base/forms/user.py @@ -102,3 +102,10 @@ class UserSettingsForm(forms.ModelForm): self.instance.set_password(password1) return self.cleaned_data + + +class User2FADeviceAddForm(forms.Form): + name = forms.CharField(label=_('Device name')) + devicetype = forms.ChoiceField(label=_('Device type'), widget=forms.RadioSelect, choices=( + ('totp', _('Smartphone with the Authenticator application')), + )) diff --git a/src/pretix/base/migrations/0039_user_require_2fa.py b/src/pretix/base/migrations/0039_user_require_2fa.py new file mode 100644 index 000000000..4e5f4dea5 --- /dev/null +++ b/src/pretix/base/migrations/0039_user_require_2fa.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2016-10-08 10:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pretixbase', '0038_auto_20160924_1448'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='require_2fa', + field=models.BooleanField(default=False), + ), + ] diff --git a/src/pretix/base/models/auth.py b/src/pretix/base/models/auth.py index af196527c..2ef8ccc00 100644 --- a/src/pretix/base/models/auth.py +++ b/src/pretix/base/models/auth.py @@ -76,6 +76,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin): timezone = models.CharField(max_length=100, default=settings.TIME_ZONE, verbose_name=_('Timezone')) + require_2fa = models.BooleanField(default=False) objects = UserManager() diff --git a/src/pretix/control/templates/pretixcontrol/base.html b/src/pretix/control/templates/pretixcontrol/base.html index 0b6b80e40..5da8f4596 100644 --- a/src/pretix/control/templates/pretixcontrol/base.html +++ b/src/pretix/control/templates/pretixcontrol/base.html @@ -19,6 +19,7 @@ + diff --git a/src/pretix/control/templates/pretixcontrol/user/2fa_add.html b/src/pretix/control/templates/pretixcontrol/user/2fa_add.html new file mode 100644 index 000000000..be599df90 --- /dev/null +++ b/src/pretix/control/templates/pretixcontrol/user/2fa_add.html @@ -0,0 +1,18 @@ +{% extends "pretixcontrol/base.html" %} +{% load i18n %} +{% load bootstrap3 %} +{% block title %}{% trans "Add a two-factor authentication device" %}{% endblock %} +{% block content %} +

{% trans "Add a two-factor authentication device" %}

+
+ {% csrf_token %} + {% bootstrap_form_errors form %} + {% bootstrap_field form.name layout='horizontal' %} + {% bootstrap_field form.devicetype layout='horizontal' %} +
+ +
+
+{% endblock %} diff --git a/src/pretix/control/templates/pretixcontrol/user/2fa_confirm_totp.html b/src/pretix/control/templates/pretixcontrol/user/2fa_confirm_totp.html new file mode 100644 index 000000000..7a1eb15a5 --- /dev/null +++ b/src/pretix/control/templates/pretixcontrol/user/2fa_confirm_totp.html @@ -0,0 +1,59 @@ +{% extends "pretixcontrol/base.html" %} +{% load i18n %} +{% load bootstrap3 %} +{% block title %}{% trans "Add a two-factor authentication device" %}{% endblock %} +{% block content %} +

{% trans "Add a two-factor authentication device" %}

+

+ {% trans "To set up this device, please follow the following steps:" %} +

+
    +
  1. + {% trans "Download the Google Authenticator application to your phone:" %} + +
  2. +
  3. + {% trans "Add a new account to the app by scanning the following barcode:" %} +
    +
  4. +
  5. + {% trans "Enter the displayed code here:" %} +
    + {% csrf_token %} + + +
    +
  6. +
+ + +{% endblock %} diff --git a/src/pretix/control/templates/pretixcontrol/user/2fa_main.html b/src/pretix/control/templates/pretixcontrol/user/2fa_main.html new file mode 100644 index 000000000..eb9d0646d --- /dev/null +++ b/src/pretix/control/templates/pretixcontrol/user/2fa_main.html @@ -0,0 +1,66 @@ +{% extends "pretixcontrol/base.html" %} +{% load i18n %} +{% load bootstrap3 %} +{% block title %}{% trans "Two-factor authentication" %}{% endblock %} +{% block content %} +

{% trans "Two-factor authentication" %}

+

+ {% blocktrans trimmed %} + Two-factor authentication is a way to add additional security to your account. If you enable it, you will + not only need your password to log in, but also an additional token that is generated e.g. by an app on your + smartphone or a hardware token generator and that changes on a regular basis. + {% endblocktrans %} +

+ {% if user.require_2fa %} +
+
+

{% trans "Two-factor status" %}

+
+
+ Disable +

+ {% trans "Two-factor authentication is currently enabled." %} +

+
+
+ {% else %} +
+
+

{% trans "Two-factor status" %}

+
+
+ {% if devices|length %} + Enable + {% endif %} +

+ {% trans "Two-factor authentication is currently disabled." %} +

+ {% if not devices|length %} +

{% trans "To enable it, you need to configure at least one device below." %}

+ {% endif %} +
+
+ {% endif %} +
+
+

{% trans "Enabled devices" %}

+
+ +
+{% endblock %} diff --git a/src/pretix/control/templates/pretixcontrol/user/settings.html b/src/pretix/control/templates/pretixcontrol/user/settings.html index e74d46426..5f7849598 100644 --- a/src/pretix/control/templates/pretixcontrol/user/settings.html +++ b/src/pretix/control/templates/pretixcontrol/user/settings.html @@ -19,6 +19,22 @@ {% bootstrap_field form.email layout='horizontal' %} {% bootstrap_field form.new_pw layout='horizontal' %} {% bootstrap_field form.new_pw_repeat layout='horizontal' %} +
+ +
+ {% if user.require_2fa %} + {% trans "Enabled" %} + + {% trans "Change settings" %} + + {% else %} + {% trans "Disabled" %} + + {% trans "Enable" %} + + {% endif %} +
+