SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 33a77c6f authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add TOTPDevice to admin

parent 39dc7b26
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ from django import forms ...@@ -8,7 +8,7 @@ from django import forms
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User, Permission from django.contrib.auth.models import User, Permission
from scipost.models import Contributor, Remark,\ from scipost.models import TOTPDevice, Contributor, Remark,\
AuthorshipClaim, PrecookedEmail,\ AuthorshipClaim, PrecookedEmail,\
EditorialCollege, EditorialCollegeFellowship, UnavailabilityPeriod EditorialCollege, EditorialCollegeFellowship, UnavailabilityPeriod
...@@ -17,6 +17,12 @@ from production.admin import ProductionUserInline ...@@ -17,6 +17,12 @@ from production.admin import ProductionUserInline
from submissions.models import Submission from submissions.models import Submission
class TOTPDeviceAdmin(admin.ModelAdmin):
search_fields = ['user',]
admin.site.register(TOTPDevice)
admin.site.register(UnavailabilityPeriod) admin.site.register(UnavailabilityPeriod)
...@@ -34,9 +40,16 @@ class ContributorInline(admin.StackedInline): ...@@ -34,9 +40,16 @@ class ContributorInline(admin.StackedInline):
min_num = 0 min_num = 0
class TOTPDeviceInline(admin.StackedInline):
model = TOTPDevice
extra = 0
min_num = 0
class UserAdmin(UserAdmin): class UserAdmin(UserAdmin):
inlines = [ inlines = [
ContributorInline, ContributorInline,
TOTPDeviceInline,
ContactInline, ContactInline,
ProductionUserInline ProductionUserInline
] ]
......
# Generated by Django 2.1.8 on 2019-08-26 07:24
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('scipost', '0026_auto_20190522_1120'),
]
operations = [
migrations.AlterModelOptions(
name='totpdevice',
options={'default_related_name': 'devices', 'verbose_name': 'TOTP Device'},
),
]
...@@ -52,6 +52,7 @@ class TOTPDevice(models.Model): ...@@ -52,6 +52,7 @@ class TOTPDevice(models.Model):
class Meta: class Meta:
default_related_name = 'devices' default_related_name = 'devices'
verbose_name = 'TOTP Device'
def __str__(self): def __str__(self):
return '{}: {}'.format(self.user, self.name) return '{}: {}'.format(self.user, self.name)
......
...@@ -23,8 +23,8 @@ class TOTPVerification: ...@@ -23,8 +23,8 @@ class TOTPVerification:
Verify a time-dependent code for a certain User. Verify a time-dependent code for a certain User.
""" """
try: try:
# Try to see if input token is convertable to integer. # Try to see if input token is convertible to integer.
# Do not actually make it a integer, because it'll loose the leading 0s. # Do not actually make it an integer, because it'll lose the leading 0s.
assert int(code) > 0 assert int(code) > 0
except (ValueError, AssertionError): except (ValueError, AssertionError):
# return False, if token could not be converted to an integer # return False, if token could not be converted to an integer
...@@ -59,8 +59,8 @@ class TOTPVerification: ...@@ -59,8 +59,8 @@ class TOTPVerification:
Independently verify a secret_key/code combination at current time. Independently verify a secret_key/code combination at current time.
""" """
try: try:
# Try to see if input token is convertable to integer. # Try to see if input token is convertible to integer.
# Do not actually make it a integer, because it'll loose the leading 0s. # Do not actually make it an integer, because it'll lose the leading 0s.
assert int(code) > 0 assert int(code) > 0
except (ValueError, AssertionError): except (ValueError, AssertionError):
# return False, if token could not be converted to an integer # return False, if token could not be converted to an integer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment