diff --git a/lab4/twidder/database.db b/lab4/twidder/database.db index b1caace054e75321c82833e45b819fe7b29e803a..645f8a9127d5be4e7627cffda1707e6fbc35c349 100644 Binary files a/lab4/twidder/database.db and b/lab4/twidder/database.db differ diff --git a/lab4/twidder/server.py b/lab4/twidder/server.py index bb8722f6606ed19c3a3057049c0ad7b65d6d4886..0d95864455839044209817b99d4dcb7f4327b7fd 100644 --- a/lab4/twidder/server.py +++ b/lab4/twidder/server.py @@ -14,15 +14,17 @@ from flask_mail import Mail, Message app = Flask(__name__, static_url_path="") -app.config.update(dict( - DEBUG = True, - MAIL_SERVER = 'smtp.gmail.com', - MAIL_PORT = 587, - MAIL_USE_TLS = True, - MAIL_USE_SSL = False, - MAIL_USERNAME = 'klasklatt3rmus1234@gmail.com', - MAIL_PASSWORD = 'wallwalla1', -)) +app.config.update( + dict( + DEBUG=True, + MAIL_SERVER="smtp.gmail.com", + MAIL_PORT=587, + MAIL_USE_TLS=True, + MAIL_USE_SSL=False, + MAIL_USERNAME="klasklatt3rmus1234@gmail.com", + MAIL_PASSWORD="wallwalla1", + ) +) mail = Mail(app) app.logger.setLevel(logging.DEBUG) @@ -138,29 +140,23 @@ def root(): return app.send_static_file("client.html") - - @app.route("/new-password", methods=["GET"]) def new_password(): print("NEW PASSWORD ENDPOINT") email = request.args.get("email") - if not is_already_user(email): - return create_response( - success=True, - message="If you have an account with this email you will receive a new password on your email shortly.", - ) - new_password = generate_token() - hashed_pw = hash_password(new_password) - database_helper.set_password(email, hashed_pw) - - msg = Message( - "New password requested", - sender="twidder@info.se", - recipients=[email], - ) - msg.body = "Your new password is: " + new_password - mail.send(msg) + if is_already_user(email): + new_password = generate_token() + hashed_pw = hash_password(new_password) + database_helper.set_password(email, hashed_pw) + + msg = Message( + "New password requested", + sender="twidder@info.se", + recipients=[email], + ) + msg.body = "Your new password is: " + new_password + mail.send(msg) return create_response( success=True, diff --git a/requirements.txt b/requirements.txt index 332cf9bfb729e67d8138488ebebedfe981e5fcae..0b858bb95f62c1a1225408b46f65927ea3498375 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask==1.1.4 +Flask-Mail==0.9.1 gevent==21.12.0 gevent-websocket==0.10.1 gunicorn==20.1.0