diff --git a/apiserver/apiserver/api/utils_stats.py b/apiserver/apiserver/api/utils_stats.py index 48fee23..199869f 100644 --- a/apiserver/apiserver/api/utils_stats.py +++ b/apiserver/apiserver/api/utils_stats.py @@ -26,6 +26,7 @@ DEFAULTS = { 'card_scans': 0, 'track': {}, 'alarm': {}, + 'sign': '', } if secrets.MUMBLE: diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index d72895b..47cd0ad 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -569,6 +569,23 @@ class StatsViewSet(viewsets.ViewSet, List): except KeyError: raise exceptions.ValidationError(dict(data='This field is required.')) + @action(detail=False, methods=['post']) + def sign(self, request): + try: + sign = request.data['sign'] + cache.set('sign', sign) + + try: + post_data = dict(access_token=secrets.SIGN_TOKEN, args=sign) + r = requests.post('https://api.particle.io/v1/devices/200042000647343232363230/text/', data=post_data, timeout=5) + r.raise_for_status() + except: + raise exceptions.ValidationError(dict(sign='Something went wrong :(')) + + return Response(200) + except KeyError: + raise exceptions.ValidationError(dict(sign='This field is required.')) + @action(detail=False, methods=['post']) def alarm(self, request): try: diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 7a18316..5462d5d 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -68,6 +68,7 @@ DOOR_CODE = '' WIFI_PASS = '' MINECRAFT = '' MUMBLE = '' +SIGN_TOKEN = '' # Portal Email Credentials # For sending password resets, etc. diff --git a/webclient/src/Home.js b/webclient/src/Home.js index 95f4a31..1aaf52f 100644 --- a/webclient/src/Home.js +++ b/webclient/src/Home.js @@ -138,6 +138,53 @@ function MemberInfo(props) { ); }; +function SignForm(props) { + const { token } = props; + const [error, setError] = useState({}); + const [sign, setSign] = useState(''); + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + + const handleValues = (e, v) => setSign(v.value); + const handleChange = (e) => handleValues(e, e.currentTarget); + + const handleSubmit = (e) => { + if (loading) return; + setLoading(true); + const data = {sign: sign}; + requester('/stats/sign/', 'POST', token, data) + .then(res => { + setLoading(false); + setSuccess(true); + setError({}); + setSign(''); + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(err.data); + }); + }; + + return ( +
+

Send a message to the sign:

+ + + + {!!token && + Submit + } + {success &&
Success!
} + + ); +}; + export function Home(props) { const { user, token } = props; const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false'))); @@ -213,9 +260,6 @@ export function Home(props) { -
Home
-

Welcome to the Protospace member portal! Here you can view member info, join classes, and manage your membership.

-
Quick Links

Main Website

Protospace Wiki[register]

@@ -306,7 +350,10 @@ export function Home(props) { {user &&

Alarm status: {alarmStat()}{doorOpenStat()}

} + +
+