From 68f9ded4842f322cd07a02943bdbab3f69f9a32f Mon Sep 17 00:00:00 2001
From: Anton <anton@hedvig.com>
Date: Tue, 22 Mar 2022 15:09:37 +0100
Subject: [PATCH] add flask mail to requirements

---
 lab4/twidder/database.db | Bin 28672 -> 28672 bytes
 lab4/twidder/server.py   |  50 ++++++++++++++++++---------------------
 requirements.txt         |   1 +
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/lab4/twidder/database.db b/lab4/twidder/database.db
index b1caace054e75321c82833e45b819fe7b29e803a..645f8a9127d5be4e7627cffda1707e6fbc35c349 100644
GIT binary patch
delta 338
zcmZp8z}WDBae_2s<wO~0#>$NeOZY`NxV|&;>GG%Yw(y<ixyxh7J)P_O#>V?x^^LL|
zT+)rTqN2jWk{lVSSq>SgSt@2KMfs(9DaE#Cre+2P1}fnpZjMRmRle>;;gtmy**Pj9
zB^42Fm5!c~hW>gUX^~!*6;7#v{?5jshS^2>9)W2^f#oR~8Ri-8xh4^%>0#NWp6T8m
zQD!-wKAD~cmCl}yj)exn<pn9Oip2%qd7dW8`B|Z1iFz5SSs5^#n&p<7o0yZjdAf8i
ziwFmQI|Ki0{;&L7`7iNL=5Oae#s7M<qC!4D4>z+kBh=j-lPBv}FrM73sNl>$+26j-
zI2kJ8mtT=*9_p5s?OW*XZRF-&6zSs~;uaj~nC5HhqiY$QSXJej;u297Z|Jzm;XXe%
P{|^QpsMgJ|{KXUigMo07

delta 151
zcmZp8z}WDBae_2s;Y1l{#=?yWOZbJ@xu-Mo>GG%Yw(y<ixyxh7J$++iBlqU%(zz@`
z?EI4%_-FHf<=@JGiGMQxDgM`+1s!VnCr{R|VD#UtsNl>$+26j-*pQi7I6287$t1BV
z&%+?XxzH>v-_XM-B&{mjKfNj>s>m$KBfzvcI6ODp$ulL*D>Bu0lf!-f$t(4_H^1^1
GQvd*pAu>Jy

diff --git a/lab4/twidder/server.py b/lab4/twidder/server.py
index bb8722f..0d95864 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 332cf9b..0b858bb 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
-- 
GitLab