From 7649bfb40e156eee821d8c3972bf69fdc8e0092a Mon Sep 17 00:00:00 2001 From: Michael Witbrock Date: Sun, 6 Oct 2024 10:41:08 +1300 Subject: [PATCH] Get signup working and login working cleanly. --- .../__pycache__/user_data.cpython-312.pyc | Bin 4820 -> 5973 bytes src/web_interface/app.py | 69 ++++++++++++++++-- src/web_interface/templates/login.html | 18 ++++- src/web_interface/templates/signup.html | 37 ++++++++++ src/web_interface/user_data.py | 37 +++++++++- ...mconnect_test.cpython-312-pytest-8.2.2.pyc | Bin 3686 -> 3686 bytes tests/test_vonlib/llmconnect_test.py | 2 +- 7 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 src/web_interface/templates/signup.html diff --git a/src/web_interface/__pycache__/user_data.cpython-312.pyc b/src/web_interface/__pycache__/user_data.cpython-312.pyc index a2ef007eb7941f5aa0c1c6a4ca68f5c34ec6838e..6debd73485a7fcad3685729c92ed04c595fdc867 100644 GIT binary patch delta 2434 zcmaJ?U2GIp6ux(6e`a>NyWQ=73+*gL%0O8VP)Y>_i@`=Is8o`Tv2J&!?Udb_I^iAH_!fd}IvCPtq;XJ&WVN^p|-=G=4c zIrrRqzH{f+Be#>0Z^PjbfoI1jbn?B}l}P)-Wf)x}Dp6^czabHAAz~d2MVaZQHY^rH)Od?J1`zGo@wD zZd6|R@-+RL#p(RBkWk=Fa-*_jDvAl#jT; z^wQwXtNdGBN3r2$(-^fiYfwJ+^xzfSHJ*4n&D&Zz?qd0 z>;tj4?FCfeA-JxWiWiH^LI*fH;`;-59*WOh#t|lTLme~Wiorhej*WLSayVUexN`*? z4ek-KPeZ+Ql-&v)>*@hrrgFi7Sl5ZKu|LIwT#2%yp{9k0wA_eW5`}kDuy%uc{lZ?o z9tG|FrD5PSx~Y!Ox#dB!7u%~P`mf~`blyh}xZ9T^Yf@rGN~}t~Yf}G;)PH^Y^X<#K zhE}Cxi`=>tUL0I+YTHnvn;p_6x`4-2^pD~dP?TiD%*zvI!BCSPm6Bj}`BW5ZtahlZ zguL|e=wR#JnPY>OY;}!mxWE9>u|-@-N93JjvzV#Y(iZvMyhr3#s!=v0YDlMZua8rVq_zS zu`jLqXzWh3Pdbmf_#^2^Cv1=kji`6hq1v{xHHh?tC>Lh1OAe+?ge)ZEW(HqcEaPfX(YY7 zQdiwxbz-xcb+)J#CX=?7DOh@b&hlYO*mO?doM~kBaSMOc)^n}~el-*Nq&0$?lL#(H z-GexV!`i0)5f0_d9<`9wp0q~6g4D2I1t{~B(jUo|pUCj9Y(Bof*QB)bE7%Q6rR~#uh;*He-g({o3%reZYge{MWktQltk*ab*p`=6#J|>$!rc6Q{ z^MRzIgq8s~3o2SX$uE(Y3G?3|OuHk23%#1Dl@lF#FPf_9@5ZDFCD#K+@DKDG)YZ<< zmd&}^6kGe}b$VM|r0)lqdV>^VP+2^r`;_a{2#Y>Rm%gRq&rn7jiX_EtDJJUDj~A74 zWN({}%zz;CGwloc4((VdY06D98ewq|_dy*LzY?5-%PSF2n z8Qm%IogAg1dq2w`NT*z-akXeQQj4}_ne}Rszgs)KP%V}!`8m7lYS)U6vt)B-$gWm* zOl}pcrt32?fFpfzUQN@GxT?Mx3YIJgsLj}xDZW?RDzU$iR~n0Lvx z#F6mez;TR=0<4hVV)3n5b|aQ;X<42V#qfCg32;EoemM9+jOTo>kyFeewMD1-$D7IgsVmmdlyxkM< zU8384)Hk%PQr~`reouM?Ql?WBOHCU=H!|zkR^Imhf=Z0zt8`WPjw_{Eu7JYNdX_oc znlCNzb7+}D@c4LFdIi;8qJL{clU1A5E9MJ)8a(*DIPU

Login

+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} +
    + {% for category, message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} + {% endwith %} +
- +


- + +


+
+

Don't have an account? Sign up here.

diff --git a/src/web_interface/templates/signup.html b/src/web_interface/templates/signup.html new file mode 100644 index 0000000..9f85d7e --- /dev/null +++ b/src/web_interface/templates/signup.html @@ -0,0 +1,37 @@ + + + + + Signup + + +

Sign Up

+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} +
    + {% for category, message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} + {% endwith %} + +
+
+

+ +
+

+ +
+

+ +
+

+ + +
+

Already have an account? Log in here.

+ + diff --git a/src/web_interface/user_data.py b/src/web_interface/user_data.py index c300953..0e10c0e 100644 --- a/src/web_interface/user_data.py +++ b/src/web_interface/user_data.py @@ -1,4 +1,6 @@ from bson.objectid import ObjectId +from werkzeug.security import generate_password_hash, check_password_hash + from vonlib import database_driver as vondb config = {} @@ -42,13 +44,36 @@ def set_userDB(cls, userdb_name=vonuserdb, usercollection_name=vonusercollection if user_collection is None: raise Exception(f"Collection {usercollection_name} does not exist and could not be created.") - # put self in 湛 Zhan von Neumarkt - user_collection.insert_one({'username': 'zhan', 'email': 'vonneumarkt@gmail.com','password': 'password'}) - cls.userdb = user_database cls.usercollection = user_collection print(f"VonUser: DB={cls.userdb.name}, Coll={cls.usercollection.name}") + @classmethod + def create_user(cls, username, email, password): + """ + Creates a new user in the user database collection. + + This method creates a new user document in the user database collection. The user document + contains the provided username, email, and password. + + Args: + username (str): The username of the new user. + email (str): The email of the new user. + password (str): The password of the new user. + + Returns: + VonUser: A VonUser object representing the new user. + """ + + user_dict = { + 'username': username, + 'email': email, + 'password': password #should be hashed by now + } + + cls.get_userCollection().insert_one(user_dict) + return VonUser(username) + @classmethod def get_userCollection(cls): return cls.usercollection @@ -64,6 +89,12 @@ def find_by_id(cls, id): return None return VonUser(vu['username']) #return VonUser object + @classmethod + def find_by_username(cls, username): + vu=cls.get_userCollection().find_one({"username": username}) + if vu is None: + return None + return VonUser(username) #return VonUser object def __init__(self, username): diff --git a/tests/test_vonlib/__pycache__/llmconnect_test.cpython-312-pytest-8.2.2.pyc b/tests/test_vonlib/__pycache__/llmconnect_test.cpython-312-pytest-8.2.2.pyc index 72c722286eef54c258ee0a236a8b718d821a18ca..0de702e404ce6a4fa4acf1a06ba71fd90e4c94ed 100644 GIT binary patch delta 22 ccmaDR^Gt^KG%qg~0}#kHq)$ diff --git a/tests/test_vonlib/llmconnect_test.py b/tests/test_vonlib/llmconnect_test.py index 0d17260..557726f 100644 --- a/tests/test_vonlib/llmconnect_test.py +++ b/tests/test_vonlib/llmconnect_test.py @@ -18,7 +18,7 @@ def test_ask_llm_1(self): #, mock_openai): assert response is not None expected_response = "os" self.assertIn(expected_response, response) - expected_response = "listdir" + expected_response = "listdir" #this doesn't always happen self.assertIn(expected_response, response)