Absolute path

This commit is contained in:
Emily 2019-03-29 11:01:31 +01:00
commit 306739df36
10 changed files with 137 additions and 13 deletions

18
main.py
View File

@ -10,21 +10,23 @@ if glob.config["git"]["auto_pull_and_restart"]: # Only used on the VPS (Do not e
@glob.app.route(glob.config["git"]["webhook_endpoint"], methods = ["POST"]) @glob.app.route(glob.config["git"]["webhook_endpoint"], methods = ["POST"])
def git_fetch(): def git_fetch():
if request.method != "POST": if request.method != "POST":
return "No" return "No", 400
data = json.loads( request.data.decode() ) data = json.loads( request.data.decode() )
if data["secret"] != glob.config["git"]["secret"]: if data["secret"] != glob.config["git"]["secret"]:
return "No" return "No", 400
import subprocess, os, sys from subprocess import check_output
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE) output = check_output(["git", "pull", "origin", "master"])
output = process.communicate()[0]
print( "GIT: {}".format( output.decode() ) )
if output.decode().split("\n")[-2].find("fail") != -1: if output.decode().split("\n")[-2].find("fail") != -1:
return "Failed to pull changes" return "Failed to pull changes", 500
# If needed; every open file or connection HAVE to be closed at this point # If needed; every open file or connection HAVE to be closed at this point
import os, sys
os.execv(sys.executable, ["python"] + sys.argv) # Restart service os.execv(sys.executable, ["python"] + sys.argv) # Restart service
if glob.config["disable-static-cache"]: if glob.config["disable-static-cache"]:
@ -37,7 +39,7 @@ if glob.config["disable-static-cache"]:
caching static files. caching static files.
""" """
return dict(url_for=dated_url_for) return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values): def dated_url_for(endpoint, **values):
if endpoint == "static": if endpoint == "static":
filename = values.get("filename", None) filename = values.get("filename", None)

View File

@ -1,7 +1,30 @@
from flask import render_template, url_for from flask import render_template, url_for, request
from objects import glob # Global sharing of python objects in a manageable way from objects import glob # Global sharing of python objects in a manageable way
@glob.app.route("/") @glob.app.route("/")
@glob.app.route("/home") @glob.app.route("/home")
def home(): def home():
return render_template("home.html") return render_template("home.html")
@glob.app.route("/login", methods = ["GET", "POST"])
def serve_login():
if request.method == "POST":
return "TODO: Login handle", 501
return render_template("login.html")
@glob.app.route("/testing")
def we_are_testing():
return render_template("testing.html")
@glob.app.route("/bill")
def serve_bill():
return render_template("bill.html")
@glob.app.route("/regninger")
def serve_regninger():
return render_template("regninger.html")
@glob.app.route("/kvittering")
def serve_kvittering():
return render_template("kvittering.html")

20
static/js/alerts.js Normal file
View File

@ -0,0 +1,20 @@
function _findAlertDom(caller) {
let selectedDOM = caller;
do {
if (selectedDOM.classList.contains("alert-section")){
return selectedDOM;
}
selectedDOM = selectedDOM.parentElement;
} while (selectedDOM != null);
throw Error("Missing alert-section class for self/parent(s)");
}
function alertAbove(caller, t, s) {
let dom = _findAlertDom(caller);
dom.outerHTML = `<div class="alert alert-${t} fade in show" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>${s}</div>` + dom.outerHTML;
}
function alertUnder(caller, t, s) {
let dom = _findAlertDom(caller);
dom.outerHTML += `<div class="alert alert-${t} fade in show" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>${s}</div>`;
}

11
templates/bill.html Normal file
View File

@ -0,0 +1,11 @@
{% set title = "bill:)" %}
{% extends "layout/bootstrap.html" %}
{% block content %}
<p>lotsa bills</p>
<p>many bills</p>
<i class="fas fa-user"></i> <!-- uses solid style -->
<i class="far fa-user"></i> <!-- uses regular style -->
<i class="fab fa-github-square"></i> <!-- uses brands style -->
{% endblock %}

10
templates/kvittering.html Normal file
View File

@ -0,0 +1,10 @@
{% set title = "Kvitteringer" %}
{% extends "layout/bootstrap.html" %}
{% block content %}
<p>Tester siden!</p>
<p>KVITTERINGER FOR FAEN!</p>
{% endblock %}

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
{% include 'includes/boot-head.html' %} {% include 'layout/includes/boot-head.html' %}
{% if title %} {% if title %}
<title>Husstanden - {{ title }}</title> <title>Husstanden - {{ title }}</title>
{% else %} {% else %}
@ -10,6 +10,6 @@
</head> </head>
<body> <body>
{% block content %}{% endblock %} {% block content %}{% endblock %}
{% include 'includes/boot-body.html' %} {% include 'layout/includes/boot-body.html' %}
</body> </body>
</html> </html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
{% include 'includes/boot-head.html' %} {% include 'layout/includes/boot-head.html' %}
{% if title %} {% if title %}
<title>Husstanden - {{ title }}</title> <title>Husstanden - {{ title }}</title>
{% else %} {% else %}
@ -10,6 +10,6 @@
</head> </head>
<body> <body>
{% block content %}{% endblock %} {% block content %}{% endblock %}
{% include 'includes/boot-body.html' %} {% include 'layout/includes/boot-body.html' %}
</body> </body>
</html> </html>

42
templates/login.html Normal file
View File

@ -0,0 +1,42 @@
{% set title = "Login" %}
{% extends "layout/bootstrap.html" %}
{% block content %}
<div class="container pt-3">
<div class="row alert-section">
<div class="col-md-8 mx-auto">
<div class="card rounded-1">
<div class="card-header">
<h3 class="mb-0">Login Methods</h3>
</div>
<div class="card-body row">
<div class="col-md-6">
<h5>Electronic ID</h5>
<p class="lead">
Secure login using Electronic ID allows Husstanden to show you banking details, bills and receipts.<br>
<a target="_blank" href="https://eid.difi.no/en/id-porten/how-obtain-electronic-id">How to obtain an Electronic ID</a>
</p>
</div>
<div class="col-md-6">
<h5>House Account</h5>
<p class="lead">
Accounts with less privileges and fast login to view non-sensitive information.<br>
Multiple house accounts can be created by logging in with house holder's verified <i>Electronic ID</i>.
</p>
</div>
</div>
<hr>
<div class="card-body row pt-2">
<div class="col-md-6 pb-2">
<a class="btn btn-primary btn-lg btn-block" href="#TODO_LOGIN_EID" onclick="alertAbove(this, 'warning', 'This should redirect the user to Electronic ID page (but due to phishing, we can not demo this)')">Electronic ID</a>
</div>
<div class="col-md-6">
<a class="btn btn-primary btn-lg btn-block" id="test" href="#TODO_LOGIN_HA" onclick="alertAbove(this, 'info', 'Unimplemented - Awaiting database')">House Account</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

8
templates/regninger.html Normal file
View File

@ -0,0 +1,8 @@
{% set title = "Regninger" %}
{% extends "layout/bootstrap.html" %}
{% block content %}
<p>Regninger :D</p>
<p>test</p>
{% endblock %}

8
templates/testing.html Normal file
View File

@ -0,0 +1,8 @@
{% set title = "testing" %}
{% extends "layout/bootstrap.html" %}
{% block content %}
<p>testing</p>
<p>tester dette</p>
{% endblock %}