Add Credential.created field

This commit is contained in:
Pēteris Caune 2020-11-12 18:02:41 +02:00
parent 53688f1d87
commit 03ea725612
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
4 changed files with 22 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# Generated by Django 3.1.2 on 2020-11-12 13:39
# Generated by Django 3.1.2 on 2020-11-12 15:29
from django.conf import settings
from django.db import migrations, models
@ -20,8 +20,9 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.UUIDField(default=uuid.uuid4, unique=True)),
('name', models.CharField(blank=True, max_length=200)),
('created', models.DateTimeField(auto_now_add=True)),
('data', models.BinaryField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='credentials', to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -397,6 +397,7 @@ class Credential(models.Model):
code = models.UUIDField(default=uuid.uuid4, unique=True)
name = models.CharField(max_length=200, blank=True)
user = models.ForeignKey(User, models.CASCADE, related_name="credentials")
created = models.DateTimeField(auto_now_add=True)
data = models.BinaryField()
def unpack(self):

View File

@ -62,3 +62,6 @@ span.loading {
text-overflow: ellipsis;
}
#my-keys th {
border-top: 0;
}

View File

@ -63,26 +63,34 @@
<div class="panel-body settings-block">
<form method="post">
{% csrf_token %}
<h2>Two Factor Authentication</h2>
<h2>Two-factor Authentication</h2>
{% if profile.user.credentials.exists %}
<table class="table">
<table id="my-keys" class="table">
<tr>
<th>Security keys</th>
</tr>
{% for credential in profile.user.credentials.all %}
<tr>
<td>{{ credential.code }}</td>
<td>{{ credential.name|default:"unnamed" }}</td>
<td>
<strong>{{ credential.name|default:"unnamed" }}</strong>
registered on {{ credential.created|date:"M j, Y" }}
</td>
<td class="text-right"><a href="#">Remove</a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>
Your account has no registered two factor authentication
methods.
Your account has no registered security keys.
Two-factor authentication is disabled.
</p>
{% endif %}
<a
href="{% url 'hc-add-credential' %}"
class="btn btn-default pull-right">Add 2FA Credential</a>
class="btn btn-default pull-right">
Register New Security Key
</a>
</form>
</div>
</div>