otp_time: fix linting

This commit is contained in:
Jens Langhammer 2020-06-30 10:42:27 +02:00
parent 812aa4ced5
commit a4c0fb9e75
9 changed files with 41 additions and 18 deletions

View file

View file

@ -0,0 +1,8 @@
from django.apps import AppConfig
class PassbookStageOTPStaticConfig(AppConfig):
name = "passbook.stages.otp_static"
label = "passbook_stages_otp_static"
verbose_name = "passbook OTP.Static"

View file

@ -1,7 +1,9 @@
"""OTP Time"""
from django.apps import AppConfig from django.apps import AppConfig
class PassbookStageOTPTimeConfig(AppConfig): class PassbookStageOTPTimeConfig(AppConfig):
"""OTP time App config"""
name = "passbook.stages.otp_time" name = "passbook.stages.otp_time"
label = "passbook_stages_otp_time" label = "passbook_stages_otp_time"

View file

@ -1,3 +1,4 @@
"""OTP Time forms"""
from django import forms from django import forms
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -15,6 +16,7 @@ class PictureWidget(forms.widgets.Widget):
class SetupForm(forms.Form): class SetupForm(forms.Form):
"""Form to setup Time-based OTP"""
title = _("Set up OTP") title = _("Set up OTP")
device: Device = None device: Device = None
@ -40,6 +42,8 @@ class SetupForm(forms.Form):
class OTPTimeStageForm(forms.ModelForm): class OTPTimeStageForm(forms.ModelForm):
"""OTP Time-based Stage setup form"""
class Meta: class Meta:
model = OTPTimeStage model = OTPTimeStage

View file

@ -1,13 +1,16 @@
"""OTP Time-based models"""
from typing import Optional from typing import Optional
from django.db import models from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from passbook.core.types import UIUserSettings from passbook.core.types import UIUserSettings
from passbook.flows.models import NotConfiguredAction, Stage from passbook.flows.models import Stage
from django.template.context import RequestContext
class TOTPDigits(models.IntegerChoices): class TOTPDigits(models.IntegerChoices):
"""OTP Time Digits"""
SIX = 6, _("6 digits, widely compatible") SIX = 6, _("6 digits, widely compatible")
EIGHT = 8, _("8 digits, not compatible with apps like Google Authenticator") EIGHT = 8, _("8 digits, not compatible with apps like Google Authenticator")
@ -21,12 +24,11 @@ class OTPTimeStage(Stage):
type = "passbook.stages.otp_time.stage.OTPTimeStageView" type = "passbook.stages.otp_time.stage.OTPTimeStageView"
form = "passbook.stages.otp_time.forms.OTPTimeStageForm" form = "passbook.stages.otp_time.forms.OTPTimeStageForm"
@staticmethod @property
def ui_user_settings(context: RequestContext) -> Optional[UIUserSettings]: def ui_user_settings(self) -> Optional[UIUserSettings]:
return UIUserSettings( return UIUserSettings(
name="Time-based OTP", name="Time-based OTP",
icon="pficon-locked", url=reverse("passbook_stages_otp_time:user-settings"),
view_name="passbook_stages_otp_time:user-settings",
) )
def __str__(self) -> str: def __str__(self) -> str:

View file

@ -1,3 +1,5 @@
"""OTP Time"""
INSTALLED_APPS = [ INSTALLED_APPS = [
"django_otp.plugins.otp_totp", "django_otp.plugins.otp_totp",
] ]

View file

@ -1,6 +1,6 @@
from typing import Any, Dict
from base64 import b32encode from base64 import b32encode
from binascii import unhexlify from binascii import unhexlify
from typing import Any, Dict
from django.contrib import messages from django.contrib import messages
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View file

@ -1,8 +1,9 @@
"""OTP Time urls"""
from django.urls import path from django.urls import path
from passbook.stages.otp_time.views import UserSettingsView, DisableView from passbook.stages.otp_time.views import DisableView, UserSettingsView
urlpatterns = [ urlpatterns = [
path("settings", UserSettingsView.as_view(), name="user-settings"), path("settings", UserSettingsView.as_view(), name="user-settings"),
path("disable", DisableView.as_view(), name="disable") path("disable", DisableView.as_view(), name="disable"),
] ]

View file

@ -1,15 +1,17 @@
"""otp time-based view"""
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.views import View
from django.views.generic import FormView, TemplateView
from django_otp.plugins.otp_totp.models import TOTPDevice
from django.contrib import messages
from passbook.audit.models import Event, EventAction
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views import View
from django.views.generic import TemplateView
from django_otp.plugins.otp_totp.models import TOTPDevice
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan from passbook.audit.models import Event, EventAction
from passbook.flows.views import SESSION_KEY_PLAN
from passbook.stages.otp_time.models import OTPTimeStage # from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan
# from passbook.flows.views import SESSION_KEY_PLAN
# from passbook.stages.otp_time.models import OTPTimeStage
class UserSettingsView(LoginRequiredMixin, TemplateView): class UserSettingsView(LoginRequiredMixin, TemplateView):
@ -34,5 +36,7 @@ class DisableView(LoginRequiredMixin, View):
totp.delete() totp.delete()
messages.success(request, "Successfully disabled Time-based OTP") messages.success(request, "Successfully disabled Time-based OTP")
# Create event with email notification # Create event with email notification
Event.new(EventAction.CUSTOM, message="User disabled Time-based OTP.").from_http(request) Event.new(
EventAction.CUSTOM, message="User disabled Time-based OTP."
).from_http(request)
return redirect("passbook_stages_otp:otp-user-settings") return redirect("passbook_stages_otp:otp-user-settings")