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

add qr code to web interface

parent f4ab4c50
No related branches found
No related tags found
No related merge requests found
/.idea /.idea
__pycache__ __pycache__
venv
flask Flask==1.0.3
\ No newline at end of file Flask-QRcode==3.0.0
psycopg2-binary==2.8.3
\ No newline at end of file
function sendToken(token) { function sendToken(token) {
const options = {filters: [{services: 'space_lock'}]};
navigator.bluetooth.requestDevice(options) navigator.bluetooth.requestDevice(options)
.then(device => { .then(device => {
console.log('> Name: ' + device.name); console.log('> Name: ' + device.name);
console.log('> Id: ' + device.id); console.log('> Id: ' + device.id);
console.log('> Connected: ' + device.gatt.connected); console.log('> Connected: ' + device.gatt.connected);
return device.gatt.connect();
})
.then(server => server.getPrimaryService('space_lock'))
.then(service => service.getCharacteristic('space_lock_token'))
.then(characteristic => {
// Writing 1 is the signal to reset energy expended.
// const token = Uint8Array.of(1);
return characteristic.writeValue(token);
})
.then(_ => {
console.log('Energy expended has been reset.');
}) })
.catch(error => { .catch(error => {
console.log('Argh! ' + error); console.log('Argh! ' + error);
... ...
......
...@@ -2,9 +2,31 @@ ...@@ -2,9 +2,31 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Spacelock</title> <title>THE ALMIGHTY ZERBEROS</title>
<link rel="stylesheet" href="{{ url_for('static', filename='bootstrap/css/bootstrap.min.css') }}">
</head> </head>
<body> <body>
{{ token }} <div class="container">
<div class="row justify-content-md-center pt-4 pb-5">
<h1>Spacelock</h1>
</div>
<div class="row justify-content-md-center">
<div class="card" style="width: 18rem;">
<div class="card-header">
<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>
<div class="text-center pt-3">
<button class="btn btn-lg btn-primary">Bluetooth</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -2,9 +2,36 @@ ...@@ -2,9 +2,36 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Spacelock</title> <title>THE ALMIGHTY ZERBEROS</title>
</head> </head>
<body> <body>
{{ error }} <div class="container">
<div class="row justify-content-md-center pt-4 pb-5">
<h1>Spacelock</h1>
</div>
<div class="row justify-content-md-center">
<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 Secret Key">
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="captcha" name="captcha">
<label class="form-check-label" for="captcha">No Bot here</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -13,22 +13,18 @@ ...@@ -13,22 +13,18 @@
<div class="row justify-content-md-center"> <div class="row justify-content-md-center">
<div class="card" style="width: 18rem;"> <div class="card" style="width: 18rem;">
<div class="card-header"> <div class="card-header">
<h5 class="card-title">Card title</h5> <h5 class="card-title">Hackerspace Access</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<form action="/" method="post"> <form action="/" method="post">
<div class="card-text"> <div class="card-text">
<div class="form-group"> <div class="form-group">
<label for="secret-key">Secret Key</label> <label for="secret-key">Secret Key</label>
<input type="password" class="form-control" id="secret-key" name='secret_key' placeholder="Your Secret Key"> <input type="password" class="form-control" id="secret-key" name='secret_key' placeholder="Your Key">
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="captcha" name="captcha">
<label class="form-check-label" for="captcha">No Bot here</label>
</div> </div>
</div> </div>
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary float-right">Submit</button>
</form> </form>
</div> </div>
</div> </div>
... ...
......
import os import os
from flask import Flask, render_template, request from flask import Flask, render_template, request
from flask_qrcode import QRcode
from utils import Database from utils import Database
app = Flask(__name__) app = Flask(__name__)
QRcode(app)
def db_config(): def db_config():
...@@ -12,8 +14,8 @@ def db_config(): ...@@ -12,8 +14,8 @@ def db_config():
'database': os.environ['SPACELOCK_DB_NAME'], 'database': os.environ['SPACELOCK_DB_NAME'],
'user': os.environ['SPACELOCK_DB_USER'], 'user': os.environ['SPACELOCK_DB_USER'],
'password': os.environ['SPACELOCK_DB_PASS'], 'password': os.environ['SPACELOCK_DB_PASS'],
'host': os.environ['SPACELOCK_DB_HOST'], 'host': os.environ.get('SPACELOCK_DB_HOST') or 'localhost',
'port': int(os.environ['SPACELOCK_DB_PORT']) 'port': int(os.environ.get('SPACELOCK_DB_PORT') or 5432)
} }
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment