Add a way to fetch a user's pubkey.

This commit is contained in:
Tom Hacohen 2020-05-24 15:20:55 +03:00
parent 47e1eec122
commit 40b7edcb84
2 changed files with 18 additions and 1 deletions

View File

@ -339,6 +339,14 @@ class UserQuerySerializer(serializers.ModelSerializer):
fields = (User.USERNAME_FIELD, User.EMAIL_FIELD)
class UserInfoPubkeySerializer(serializers.ModelSerializer):
pubkey = BinaryBase64Field()
class Meta:
model = models.UserInfo
fields = ('pubkey', )
class AuthenticationSignupSerializer(serializers.Serializer):
user = UserQuerySerializer(many=False)
salt = BinaryBase64Field()

View File

@ -34,7 +34,7 @@ import nacl.secret
import nacl.hash
from . import app_settings, permissions
from .models import Collection, CollectionItem, CollectionItemRevision, CollectionMember, CollectionInvitation
from .models import Collection, CollectionItem, CollectionItemRevision, CollectionMember, CollectionInvitation, UserInfo
from .serializers import (
b64encode,
AuthenticationSignupSerializer,
@ -50,6 +50,7 @@ from .serializers import (
CollectionMemberSerializer,
CollectionInvitationSerializer,
InvitationAcceptSerializer,
UserInfoPubkeySerializer,
UserSerializer,
)
@ -456,6 +457,14 @@ class CollectionInvitationViewSet(BaseViewSet):
return queryset.filter(fromMember__collection=collection)
@action_decorator(detail=False, allowed_methods=['GET'], methods=['GET'])
def fetch_user_profile(self, request, collection_uid=None):
username = request.GET.get('username')
kwargs = {'owner__' + User.USERNAME_FIELD: username}
user_info = get_object_or_404(UserInfo.objects.all(), **kwargs)
serializer = UserInfoPubkeySerializer(user_info)
return Response(serializer.data)
class InvitationIncomingViewSet(BaseViewSet):
allowed_methods = ['GET', 'DELETE']