diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 096880f..b962dcd 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -9,7 +9,7 @@ from rest_auth.serializers import UserDetailsSerializer import re from . import models, fields, utils, utils_ldap -from .. import settings +from .. import settings, secrets class TransactionSerializer(serializers.ModelSerializer): # fields directly from old portal. replace with slugs we want @@ -341,6 +341,8 @@ class UserSerializer(serializers.ModelSerializer): training = UserTrainingSerializer(many=True) member = MemberSerializer() transactions = serializers.SerializerMethodField() + door_code = serializers.SerializerMethodField() + wifi_pass = serializers.SerializerMethodField() class Meta: model = User @@ -351,7 +353,9 @@ class UserSerializer(serializers.ModelSerializer): 'transactions', 'cards', 'training', - 'is_staff' + 'is_staff', + 'door_code', + 'wifi_pass', ] depth = 1 @@ -363,6 +367,18 @@ class UserSerializer(serializers.ModelSerializer): serializer.is_valid() return serializer.data + def get_door_code(self, obj): + if not obj.member.paused_date and obj.cards.count(): + return secrets.DOOR_CODE + else: + return None + + def get_wifi_pass(self, obj): + if not obj.member.paused_date: + return secrets.WIFI_PASS + else: + return None + class MyRegisterSerializer(RegisterSerializer): first_name = serializers.CharField(max_length=32) diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 88c959f..fced6cd 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -33,6 +33,10 @@ LDAP_API_KEY = '' # head /dev/urandom | base32 | head -c 40 DOOR_API_TOKEN = '' +# Protospace general info +DOOR_CODE = '' +WIFI_PASS = '' + # Backup API tokens # These tokens allow each user to download a backup of member data. # Don't mess up the data structure!