It finally takes homework automatically, I just have to enter the dates and upload them to the database - I started a very basic but still very broken login system.

This commit is contained in:
Stefano Assenzo
2023-01-08 15:33:16 +00:00
parent f7ce81ef5d
commit f4341ea442
3 changed files with 208 additions and 85 deletions

34
app.py
View File

@ -1,5 +1,6 @@
from flask import Flask, render_template, request, session, jsonify
from flask import Flask, render_template, request, session, jsonify, redirect
import requests
import pymongo
import logging
import bcrypt
import sys
@ -45,6 +46,37 @@ def api():
if(request.method == 'GET'):
data = "hello world"
return jsonify({'data': data})
@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)
if __name__ == '__main__':
logging.info("Web server started!")