From f7d2e8563b50412d94f820bce6e0b5a5448dddc6 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 12 Feb 2023 12:29:18 +0100 Subject: [PATCH] addd password recovery --- __pycache__/database.cpython-310.pyc | Bin 1162 -> 2350 bytes __pycache__/mail.cpython-310.pyc | Bin 0 -> 957 bytes database.json | 15 +++- database.py | 46 ++++++++-- .../2029240f6d1128be89ddc32729463129 | Bin 9 -> 9 bytes .../320444fe8859cda10187fa078aaa3674 | Bin 49 -> 0 bytes mail.py | 8 +- main.py | 40 +++++++-- templates/connected.html | 14 +++ templates/error.html | 16 ++++ templates/forgot.html | 83 ++++++++++++++++++ templates/mails/password_recovery.html | 76 ++++++++++++++++ templates/reset.html | 83 ++++++++++++++++++ 13 files changed, 362 insertions(+), 19 deletions(-) create mode 100644 __pycache__/mail.cpython-310.pyc delete mode 100644 flask_session/320444fe8859cda10187fa078aaa3674 create mode 100644 templates/connected.html create mode 100644 templates/error.html create mode 100644 templates/forgot.html create mode 100644 templates/mails/password_recovery.html create mode 100644 templates/reset.html diff --git a/__pycache__/database.cpython-310.pyc b/__pycache__/database.cpython-310.pyc index 7b9825e21f446bcd229d26411385eb6bea224275..bea011148a7a1b77b8b3dd82dd9adb11462e1482 100644 GIT binary patch literal 2350 zcmaJ?OLH4V5T2QRSe9j3mX+9Y-XR4Dh!r3}4irT}uDC*((_U07_1KcFhnX2AQA#;E z9Qg+v(mwXwC^a0f@%$Gh*sJsfS0*Y3l6INAcW zCn^uliJyv>gg>>qgQwpm!HcFgIthO4Yctq=wYF1**v0kO>YYQ|>z)&Z6`6#sF6gdH zg1*(pHb}|*qj2y&zBYrxiIF@Nd*V#)R+L%7nZ%3R?K5F0S}gu~RBiS;x@ui)y75t~ zTYajZSD&HkUiI1F2i@)OwVa+oIUXd-2in!xI%%!nv74Vydc+{7>W}K;>g<* zhIE{zr}0B-7mcs5!J2;AvW|>gkg}XKW&FI;khxBpNV(Z0u|;AUsnn}1yUTic_crah zfg;Hq$JV~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u2FcUKS=dJs<=wu#K=>#ny;UY5rZimZPcZ+LfOQ)abul7v44t9>_IAoooWlc zHBGDr`=IWj@E_uhc~XxMHCv%BxB$Vw@dJi$hGQMh!Y!cSOWJR@b4BG}T_c@&Q*-?I zS>)N4mJZIW^m;QRwc0_SxRU8arz5HMP}_tX_6M>*Ox8v1ql@;Dh0p?Q`F#{iUr8;E zj>6bC_?kpdQEo*&w;4(XM><~GECW%^?P({{b@Sh*gl)o)9j((c|2YWX}a2zT#UHTPM!&+ zU7pY=)+DD=o@RpSDvM+u({V4Q3D?AUdz3Nl%i-ZM50$PKP?)8Prz(U7{y(O11o$Pe z`~pIu3v_NP%y0uuZDwtvsnIrQ4B7#0&n#t6E#_WWbBvL4X6_uFJIXuuA)|np+qFR=UDW{#kjB<}jXjFdzr$q8L>dJx21)DZF9mJupKs zjLM!cB?r!q$dbT1$b?xA?F>{B3kR;k1p%Y+iyxmUVSXum16G6uN_*hxM@QPDO3`p2 zOiQ#4^V6%L;8gJ*<9!NK?)^;xy-ZXdM~4CFb`JJ?-R`b-`5h} z^r-2Hl6lh bool: + return (get_user_by_email(email) != None) def user_exist(email: str): return (get_user_by_email(email) != None) def add_user(email: str, password: str): password_hashed = hasher.hash_text(password) - users.insert({email: str(password_hashed)}); + users.insert({"email": email, "password": str(password_hashed)}); def check_password(email: str, password: str): - password_hashed = get_user_by_email(email).get(email) + password_hashed = get_user_by_email(email).get("password") password_hashed = bytes(password_hashed[2:-1], "utf-8") return (hasher.is_same(password, password_hashed)) +def change_user_password(email: str, password: str): + password_hashed = hasher.hash_text(password) + db.update({"password": password_hashed}, query.email == email) + resets = db.table("resets") + +def get_email_by_reset_code(code: str): + user_lst = resets.search(query.code == code) + if (user_lst == []): + return (None) + return (user_lst[0]) + +def reset_code_exist(code: str) -> bool: + return (get_email_by_reset_code(code) != None) + +def remove_reset_code_by_email(email: str): + resets.remove(query.email == email) + +def remove_reset_code_by_code(code: str): + resets.remove(query.code == code) + +def create_reset_code_by_email(email: str): + code = str(uuid.uuid4()); + remove_reset_code_by_email(email); + resets.insert({"email": email, "code": code}) + return (code) diff --git a/flask_session/2029240f6d1128be89ddc32729463129 b/flask_session/2029240f6d1128be89ddc32729463129 index 8b04914a5e6ad4858df0019a6abe09326d3863de..60b84f8bf0af235343c89653c31a85c904ebfc66 100644 GIT binary patch literal 9 QcmZQzU|?uq^=8lm00XQ5{{R30 literal 9 QcmZQzU|?uq^=8xq00XW800000 diff --git a/flask_session/320444fe8859cda10187fa078aaa3674 b/flask_session/320444fe8859cda10187fa078aaa3674 deleted file mode 100644 index e53970ba5221c845c713e7fbb8584a0cf5494709..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 zcmcER6-a4dovOqD0ku") def reset(uuid): - return ("bozo") + if (not database.reset_code_exist(uuid)): + return (render_template("error.html", error="code inconnu")) + email = database.get_email_by_reset_code(uuid) + email = email["email"] + return (render_template("reset.html", email=email)) + +@app.route("/reset/", methods=['POST']) +def reset_post(uuid): + if (not database.reset_code_exist(uuid)): + return (render_template("error.html", error="code inconnu")) + email = database.get_email_by_reset_code(uuid) + password = request.form.get('password') + repassword = request.form.get('repassword') + if (password != repassword): + return (render_template("reset.html", error="Les deux mots de passe sont differents")) + database.change_user_password(email, password); + database.remove_reset_code_by_code(uuid); + return (redirect("/login")) @app.route("/join/") def join(uuid): diff --git a/templates/connected.html b/templates/connected.html new file mode 100644 index 0000000..26e0556 --- /dev/null +++ b/templates/connected.html @@ -0,0 +1,14 @@ + + + + + PyMenu + + +

connected

+

Welcome to FlaskApp!

+ + + + + diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..3f1c7c7 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,16 @@ + + + + + PyMenu + + +

Error

+ {% if error %} +

{{error}}

+ {% endif %} + + + + + diff --git a/templates/forgot.html b/templates/forgot.html new file mode 100644 index 0000000..2a49a8b --- /dev/null +++ b/templates/forgot.html @@ -0,0 +1,83 @@ + + + + + + + + Beyond School + + +
+
+

Mot de passe oublié ?

+ + +
+ {% if error %} +

{{error}}

+ {% endif %} + + + + +
+
+ + + diff --git a/templates/mails/password_recovery.html b/templates/mails/password_recovery.html new file mode 100644 index 0000000..ee73186 --- /dev/null +++ b/templates/mails/password_recovery.html @@ -0,0 +1,76 @@ + + + + + + + + Beyond School + + +
+
+

Mot de passe oublié ?

+ + + +
+
+ + + diff --git a/templates/reset.html b/templates/reset.html new file mode 100644 index 0000000..a7c4fef --- /dev/null +++ b/templates/reset.html @@ -0,0 +1,83 @@ + + + + + + + + Beyond School + + +
+
+

Connection

+ + +
+ + +
+ + +
+ +
+
+ + +