Add fields for Protospace wifi pass and door code

This commit is contained in:
Tanner Collin 2020-02-29 00:49:58 +00:00
parent 1cc3087148
commit 8ff4997810
2 changed files with 22 additions and 2 deletions

View File

@ -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)

View File

@ -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!