Skip to content
Snippets Groups Projects
Commit ee282aa6 authored by Michael Loipführer's avatar Michael Loipführer
Browse files

fix working bluetooth to make it more working

parent ea8dd590
No related branches found
No related tags found
No related merge requests found
function sendToken(token) {
console.log('Sending token: ' + token);
const serviceUUID = '12345678-1234-5678-1234-56789abcdef0';
const characteristicUUID = '12345678-1234-5678-1234-56789abcdef5';
const options = {
......@@ -20,13 +22,14 @@ function sendToken(token) {
.then(server => server.getPrimaryService(serviceUUID))
.then(service => service.getCharacteristic(characteristicUUID))
.then(characteristic => {
const t = Uint8Array.from(atob(token), c => c.charCodeAt(0));
const t = Uint8Array.from(token, c => c.charCodeAt(0));
return characteristic.writeValue(t);
})
.then(_ => {
console.log('Successfully sent token:', token);
alert('Successfully sent token!');
})
.catch(error => {
alert('Something went wrong:\n' + error);
console.log('Argh! ' + error);
});
}
{% extends "base.html" %}
{% block content %}
<div class="card" style="width: 18rem;">
<div class="card-header">
<div class="card">
<div class="card-header bg-success text-white">
<h5 class="card-title">Access Granted</h5>
</div>
<div class="card-body">
<div class="card-text">
<div class="row">
<img src="{{ qrcode(token) }}" alt="{{ token }}" style="max-width: 100%;">
<div class="text-center">
<img src="{{ qrcode(token) }}" alt="{{ token }}">
</div>
<div class="text-center pt-3">
<div class="pt-3 text-center">
<button class="btn btn-lg btn-primary" onclick="sendToken('{{ token }}')">Bluetooth</button>
</div>
</div>
......
......
......@@ -7,31 +7,16 @@
</head>
<body>
<div class="container">
<div class="row justify-content-md-center pt-4 pb-5">
<div class="row justify-content-center pt-4 pb-5">
<h1>Spacelock</h1>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-12 col-md-8 col-xl-5">
{% block content %}
<div class="card" style="width: 18rem;">
<div class="card-header">
<h5 class="card-title">Hackerspace Access</h5>
</div>
<div class="card-body">
<form action="/" method="post">
<div class="card-text">
<div class="form-group">
<label for="secret-key">Secret Key</label>
<input type="password" class="form-control" id="secret-key" name='secret_key' placeholder="Your Key">
</div>
</div>
<button type="submit" class="btn btn-primary float-right">Submit</button>
</form>
</div>
</div>
{% endblock %}
</div>
</div>
</div>
{% block scripts %}
<script type="application/javascript" src="{{ url_for('static', filename='js/script.js') }}"></script>
......
......
{% extends "base.html" %}
{% block content %}
<div class="card" style="width: 18rem;">
<div class="card">
<div class="card-header text-white bg-danger">
<h5 class="card-title">Access Denied</h5>
</div>
......
......
{% extends "base.html" %}
{% block content %}
<div class="card" style="width: 18rem;">
<div class="card">
<div class="card-header">
<h5 class="card-title">Hackerspace Access</h5>
</div>
......
......
......@@ -29,7 +29,6 @@ def gen_token(key):
def index():
if request.method == 'POST':
token = gen_token(request.form['secret_key'])
print(token)
if token is None:
return render_template('error.html', error='DENIED!!!')
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment