Browse Source

Add Credential.created field

pull/456/head
Pēteris Caune 4 years ago
parent
commit
03ea725612
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 22 additions and 9 deletions
  1. +3
    -2
      hc/accounts/migrations/0034_credential.py
  2. +1
    -0
      hc/accounts/models.py
  3. +3
    -0
      static/css/profile.css
  4. +15
    -7
      templates/accounts/profile.html

+ 3
- 2
hc/accounts/migrations/0034_credential.py 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.conf import settings
from django.db import migrations, models 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')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.UUIDField(default=uuid.uuid4, unique=True)), ('code', models.UUIDField(default=uuid.uuid4, unique=True)),
('name', models.CharField(blank=True, max_length=200)), ('name', models.CharField(blank=True, max_length=200)),
('created', models.DateTimeField(auto_now_add=True)),
('data', models.BinaryField()), ('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)),
], ],
), ),
] ]

+ 1
- 0
hc/accounts/models.py View File

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


+ 3
- 0
static/css/profile.css View File

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

+ 15
- 7
templates/accounts/profile.html View File

@ -63,26 +63,34 @@
<div class="panel-body settings-block"> <div class="panel-body settings-block">
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
<h2>Two Factor Authentication</h2>
<h2>Two-factor Authentication</h2>
{% if profile.user.credentials.exists %} {% 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 %} {% for credential in profile.user.credentials.all %}
<tr> <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> </tr>
{% endfor %} {% endfor %}
</table> </table>
{% else %} {% else %}
<p> <p>
Your account has no registered two factor authentication
methods.
Your account has no registered security keys.
Two-factor authentication is disabled.
</p> </p>
{% endif %} {% endif %}
<a <a
href="{% url 'hc-add-credential' %}" 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> </form>
</div> </div>
</div> </div>


Loading…
Cancel
Save