Add simple support for PGP keys

This commit is contained in:
Danielle McLean 2017-10-23 12:33:24 +11:00
parent 0e3ef423d2
commit 75f2575c30
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
4 changed files with 56 additions and 1 deletions

View file

@ -7,6 +7,14 @@
<h4 class="card-title p-name">
<span class="p-given-name">{{ user.first_name }}</span> <span class="p-family-name">{{ user.last_name }}</span>
</h4>
{% for key in user.keys.all %}
<h6 class="card-subtitle">
<a class="u-key" href="{{ key.file.url }}">
<i class="fa fa-key"></i>
{{ key.pretty_print }}
</a>
</h6>
{% endfor %}
{% if user.note %}<p class="card-text p-note">{{ user.note }}</p>{% endif %}
</div>

View file

@ -1,12 +1,20 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User
from .models import Key, User
class KeyInline(admin.TabularInline):
model = Key
extra = 1
class UserAdmin(BaseUserAdmin):
fieldsets = BaseUserAdmin.fieldsets + (
('Profile', {'fields': ('avatar', 'note')}),
)
inlines = (
KeyInline,
)
admin.site.register(User, UserAdmin)

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-23 01:25
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0002_auto_20171023_0109'),
]
operations = [
migrations.CreateModel(
name='Key',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('fingerprint', models.CharField(max_length=40)),
('file', models.FileField(upload_to='keys')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='keys', to=settings.AUTH_USER_MODEL)),
],
),
]

View file

@ -9,3 +9,16 @@ def avatar_path(instance, name):
class User(AbstractUser):
avatar = models.ImageField(upload_to=avatar_path)
note = models.TextField(blank=True)
class Key(models.Model):
user = models.ForeignKey(
User,
related_name='keys',
on_delete=models.CASCADE
)
fingerprint = models.CharField(max_length=40)
file = models.FileField(upload_to='keys')
def pretty_print(self):
return " ".join(self.fingerprint[i:i+4] for i in range(0, 40, 4))