Add input box for sending messages to the sign
This commit is contained in:
parent
e501427f38
commit
7b5dac7c6e
|
@ -26,6 +26,7 @@ DEFAULTS = {
|
||||||
'card_scans': 0,
|
'card_scans': 0,
|
||||||
'track': {},
|
'track': {},
|
||||||
'alarm': {},
|
'alarm': {},
|
||||||
|
'sign': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
if secrets.MUMBLE:
|
if secrets.MUMBLE:
|
||||||
|
|
|
@ -569,6 +569,23 @@ class StatsViewSet(viewsets.ViewSet, List):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.ValidationError(dict(data='This field is required.'))
|
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'])
|
@action(detail=False, methods=['post'])
|
||||||
def alarm(self, request):
|
def alarm(self, request):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -68,6 +68,7 @@ DOOR_CODE = ''
|
||||||
WIFI_PASS = ''
|
WIFI_PASS = ''
|
||||||
MINECRAFT = ''
|
MINECRAFT = ''
|
||||||
MUMBLE = ''
|
MUMBLE = ''
|
||||||
|
SIGN_TOKEN = ''
|
||||||
|
|
||||||
# Portal Email Credentials
|
# Portal Email Credentials
|
||||||
# For sending password resets, etc.
|
# For sending password resets, etc.
|
||||||
|
|
|
@ -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 (
|
||||||
|
<Form onSubmit={handleSubmit}>
|
||||||
|
<p>Send a message to the sign:</p>
|
||||||
|
|
||||||
|
<Form.Input
|
||||||
|
name='sign'
|
||||||
|
onChange={handleChange}
|
||||||
|
value={sign}
|
||||||
|
error={error.sign}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!!token &&<Form.Button loading={loading} error={error.non_field_errors}>
|
||||||
|
Submit
|
||||||
|
</Form.Button>}
|
||||||
|
{success && <div>Success!</div>}
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export function Home(props) {
|
export function Home(props) {
|
||||||
const { user, token } = props;
|
const { user, token } = props;
|
||||||
const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false')));
|
const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false')));
|
||||||
|
@ -213,9 +260,6 @@ export function Home(props) {
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<Segment>
|
<Segment>
|
||||||
<Header size='medium'>Home</Header>
|
|
||||||
<p>Welcome to the Protospace member portal! Here you can view member info, join classes, and manage your membership.</p>
|
|
||||||
|
|
||||||
<Header size='medium'>Quick Links</Header>
|
<Header size='medium'>Quick Links</Header>
|
||||||
<p><a href='http://protospace.ca/' target='_blank' rel='noopener noreferrer'>Main Website</a></p>
|
<p><a href='http://protospace.ca/' target='_blank' rel='noopener noreferrer'>Main Website</a></p>
|
||||||
<p><a href='http://wiki.protospace.ca/Welcome_to_Protospace' target='_blank' rel='noopener noreferrer'>Protospace Wiki</a> — <Link to='/auth/wiki'>[register]</Link></p>
|
<p><a href='http://wiki.protospace.ca/Welcome_to_Protospace' target='_blank' rel='noopener noreferrer'>Protospace Wiki</a> — <Link to='/auth/wiki'>[register]</Link></p>
|
||||||
|
@ -306,7 +350,10 @@ export function Home(props) {
|
||||||
{user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>}
|
{user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<SignForm token={token} />
|
||||||
|
|
||||||
</Segment>
|
</Segment>
|
||||||
|
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user