-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
73 lines (46 loc) · 1.48 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Author: H. Frederich (h.frederich@protonmail.com)
# Date: 2023-06-16
# Version: 1.0.2
import fido2.features
from flask import Flask, redirect, render_template, session
from secrets import token_bytes
import api
# Transforms bytes into JSON-friendly Base64 encoded strings.
fido2.features.webauthn_json_mapping.enabled = True
# Creating a new Flask app.
app = Flask(import_name=__name__, static_url_path='')
# Secret key for signing the session cookie.
app.secret_key = token_bytes(nbytes=32)
# Registering the API blueprint.
app.register_blueprint(blueprint=api.bp)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/register')
def register():
if check_login_status():
return redirect('/')
return render_template('register.html')
@app.route('/login')
def login():
if check_login_status():
return redirect('/')
return render_template('login.html')
@app.route('/logout')
def logout():
# Removing the user information from the session, thereby logging them out.
session.pop('username')
session.pop('display_name')
return redirect('/')
@app.context_processor
def display_status():
if check_login_status():
return dict(login=True)
return dict(login=False)
def check_login_status():
if 'username' in session:
return True
return False
if __name__ == '__main__':
# Runs the server in an SSL context with an automatically created SSL-certificate.
app.run(ssl_context='adhoc')