2023-01-08 16:33:16 +01:00
|
|
|
from flask import Flask, render_template, request, session, jsonify, redirect
|
2022-12-05 16:13:40 +01:00
|
|
|
import requests
|
2023-01-08 16:33:16 +01:00
|
|
|
import pymongo
|
2023-01-07 12:44:09 +01:00
|
|
|
import logging
|
2022-12-28 16:04:42 +01:00
|
|
|
import bcrypt
|
2023-01-07 12:44:09 +01:00
|
|
|
import sys
|
2022-12-05 16:13:40 +01:00
|
|
|
import os
|
|
|
|
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
|
|
|
handlers=[
|
|
|
|
logging.FileHandler("src/log/all.log"),
|
|
|
|
logging.StreamHandler(sys.stdout)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-12-05 16:13:40 +01:00
|
|
|
app = Flask(__name__)
|
|
|
|
IMAGE_FOLDER = os.path.join('static', 'images')
|
|
|
|
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def homepage():
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.info("A user went up: Homepage")
|
2022-12-05 16:13:40 +01:00
|
|
|
return render_template('html/index.html')
|
|
|
|
#imageList = os.listdir('static/images')
|
|
|
|
#imageList = ['images/' + image for image in imageList]
|
|
|
|
#return render_template('go.html', imageList=imageList)
|
|
|
|
|
|
|
|
@app.route('/orario')
|
|
|
|
def orario():
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.info("A user went up: Orario")
|
2022-12-28 16:04:42 +01:00
|
|
|
if 'username' in session:
|
|
|
|
return "You are logged in as " + session['username']
|
|
|
|
#return render_template('html/orario.html')
|
2022-12-05 16:13:40 +01:00
|
|
|
|
|
|
|
@app.route('/calendario')
|
|
|
|
def calendario():
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.info("A user went up: Calendario")
|
2022-12-05 16:13:40 +01:00
|
|
|
return render_template('html/calendario.html')
|
|
|
|
|
2022-12-28 16:04:42 +01:00
|
|
|
# Da sistemare
|
2022-12-24 17:38:40 +01:00
|
|
|
@app.route('/api', methods = ['GET', 'POST'])
|
|
|
|
def api():
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.info("A user went up: API")
|
2022-12-24 17:38:40 +01:00
|
|
|
if(request.method == 'GET'):
|
|
|
|
data = "hello world"
|
|
|
|
return jsonify({'data': data})
|
2023-01-08 16:33:16 +01:00
|
|
|
|
|
|
|
@app.route('/login', methods = ['GET', 'POST'])
|
|
|
|
def login():
|
|
|
|
#Create login with Mongodb
|
|
|
|
logging.info("A user went up: Login")
|
|
|
|
message = 'Please login to your account'
|
|
|
|
if "email" in session:
|
|
|
|
return redirect(url_for("logged_in"))
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
email = request.form.get("email")
|
|
|
|
password = request.form.get("password")
|
|
|
|
|
|
|
|
|
|
|
|
email_found = records.find_one({"email": email})
|
|
|
|
if email_found:
|
|
|
|
email_val = email_found['email']
|
|
|
|
passwordcheck = email_found['password']
|
|
|
|
|
|
|
|
if bcrypt.checkpw(password.encode('utf-8'), passwordcheck):
|
|
|
|
session["email"] = email_val
|
|
|
|
return redirect(url_for('logged_in'))
|
|
|
|
else:
|
|
|
|
if "email" in session:
|
|
|
|
return redirect(url_for("logged_in"))
|
|
|
|
message = 'Wrong password'
|
|
|
|
return render_template('login.html', message=message)
|
|
|
|
else:
|
|
|
|
message = 'Email not found'
|
|
|
|
return render_template('login.html', message=message)
|
|
|
|
return render_template('login.html', message=message)
|
2022-12-24 17:38:40 +01:00
|
|
|
|
2022-12-05 16:13:40 +01:00
|
|
|
if __name__ == '__main__':
|
2023-01-07 12:44:09 +01:00
|
|
|
logging.info("Web server started!")
|
2022-12-05 16:13:40 +01:00
|
|
|
app.run()
|