From c2d72be6a3f8109ddf4c4af0c3a5647b049d5cab Mon Sep 17 00:00:00 2001 From: Charaka V Mihiranga <143955766+CharakaMihiranga@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:58:30 +0530 Subject: [PATCH] Python-MySQL-Integration:Implemented an HTML/CSS user registration form and integrated it with a Flask backend. The form uses JavaScript to submit data via `fetch` with `application/x-www-form-urlencoded` encoding. The Flask backend processes and saves the user data to a MySQL database. --- JWT/JWT-Frontend/.idea/.gitignore | 8 +++ JWT/JWT-Frontend/.idea/JWT-Frontend.iml | 9 +++ JWT/JWT-Frontend/.idea/misc.xml | 6 ++ JWT/JWT-Frontend/.idea/modules.xml | 8 +++ JWT/JWT-Frontend/.idea/vcs.xml | 6 ++ Python-MySQL-Integration/.idea/.gitignore | 8 +++ .../.idea/Python-MySQL-Integration.iml | 21 ++++++ .../.idea/dataSources.xml | 12 ++++ .../inspectionProfiles/Project_Default.xml | 7 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ Python-MySQL-Integration/.idea/misc.xml | 7 ++ Python-MySQL-Integration/.idea/modules.xml | 8 +++ Python-MySQL-Integration/.idea/vcs.xml | 6 ++ .../__pycache__/app.cpython-312.pyc | Bin 0 -> 1428 bytes Python-MySQL-Integration/app.py | 29 ++++++++ Python-MySQL-Integration/entity/User.py | 34 +++++++++ .../entity/__pycache__/User.cpython-312.pyc | Bin 0 -> 2167 bytes Python-MySQL-Integration/model/UserModel.py | 16 +++++ .../__pycache__/UserModel.cpython-312.pyc | Bin 0 -> 1133 bytes Python-MySQL-Integration/static/js/index.js | 29 ++++++++ Python-MySQL-Integration/templates/index.html | 67 ++++++++++++++++++ 21 files changed, 287 insertions(+) create mode 100644 JWT/JWT-Frontend/.idea/.gitignore create mode 100644 JWT/JWT-Frontend/.idea/JWT-Frontend.iml create mode 100644 JWT/JWT-Frontend/.idea/misc.xml create mode 100644 JWT/JWT-Frontend/.idea/modules.xml create mode 100644 JWT/JWT-Frontend/.idea/vcs.xml create mode 100644 Python-MySQL-Integration/.idea/.gitignore create mode 100644 Python-MySQL-Integration/.idea/Python-MySQL-Integration.iml create mode 100644 Python-MySQL-Integration/.idea/dataSources.xml create mode 100644 Python-MySQL-Integration/.idea/inspectionProfiles/Project_Default.xml create mode 100644 Python-MySQL-Integration/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 Python-MySQL-Integration/.idea/misc.xml create mode 100644 Python-MySQL-Integration/.idea/modules.xml create mode 100644 Python-MySQL-Integration/.idea/vcs.xml create mode 100644 Python-MySQL-Integration/__pycache__/app.cpython-312.pyc create mode 100644 Python-MySQL-Integration/app.py create mode 100644 Python-MySQL-Integration/entity/User.py create mode 100644 Python-MySQL-Integration/entity/__pycache__/User.cpython-312.pyc create mode 100644 Python-MySQL-Integration/model/UserModel.py create mode 100644 Python-MySQL-Integration/model/__pycache__/UserModel.cpython-312.pyc create mode 100644 Python-MySQL-Integration/static/js/index.js create mode 100644 Python-MySQL-Integration/templates/index.html diff --git a/JWT/JWT-Frontend/.idea/.gitignore b/JWT/JWT-Frontend/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/JWT/JWT-Frontend/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/JWT/JWT-Frontend/.idea/JWT-Frontend.iml b/JWT/JWT-Frontend/.idea/JWT-Frontend.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/JWT/JWT-Frontend/.idea/JWT-Frontend.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/JWT/JWT-Frontend/.idea/misc.xml b/JWT/JWT-Frontend/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/JWT/JWT-Frontend/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/JWT/JWT-Frontend/.idea/modules.xml b/JWT/JWT-Frontend/.idea/modules.xml new file mode 100644 index 0000000..899d49e --- /dev/null +++ b/JWT/JWT-Frontend/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/JWT/JWT-Frontend/.idea/vcs.xml b/JWT/JWT-Frontend/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/JWT/JWT-Frontend/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/.gitignore b/Python-MySQL-Integration/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Python-MySQL-Integration/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Python-MySQL-Integration/.idea/Python-MySQL-Integration.iml b/Python-MySQL-Integration/.idea/Python-MySQL-Integration.iml new file mode 100644 index 0000000..9b09070 --- /dev/null +++ b/Python-MySQL-Integration/.idea/Python-MySQL-Integration.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/dataSources.xml b/Python-MySQL-Integration/.idea/dataSources.xml new file mode 100644 index 0000000..256f380 --- /dev/null +++ b/Python-MySQL-Integration/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306/se10sessions + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/inspectionProfiles/Project_Default.xml b/Python-MySQL-Integration/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..45f4b3a --- /dev/null +++ b/Python-MySQL-Integration/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/inspectionProfiles/profiles_settings.xml b/Python-MySQL-Integration/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/Python-MySQL-Integration/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/misc.xml b/Python-MySQL-Integration/.idea/misc.xml new file mode 100644 index 0000000..756d868 --- /dev/null +++ b/Python-MySQL-Integration/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/modules.xml b/Python-MySQL-Integration/.idea/modules.xml new file mode 100644 index 0000000..cba1fd1 --- /dev/null +++ b/Python-MySQL-Integration/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/.idea/vcs.xml b/Python-MySQL-Integration/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Python-MySQL-Integration/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Python-MySQL-Integration/__pycache__/app.cpython-312.pyc b/Python-MySQL-Integration/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..307ccd067fcfbf5d7d93fcf2b2bfb51883eefebe GIT binary patch literal 1428 zcmbVL&1)M+6rb4-t)yK=Zj_{zZR|iS@V3OR36#=`p6oaQ$4ya7K^T@LJGSKPYUSBg zQW+T((h~dRV|?_rIM@Ca?IEfTGJ``~(jIzKuuneay_MH;1HI(IypNfA@6GSMH@{{w zX#(_%|L5v&5+SeAh)Fq9js+;si9;Of5|5UtCzT~nF3S}6BvkSUb+e22NGboRl;Br+Jdjz0qSoP=li;jJ`AS|X;jyqT^-wjX9Hp$CCE z7X4>(44j-6=f7B4oG&eW_W4R_VeZq2T`#d9sQR^F<$g1)__dq&nx$`+Zr-hhY>nF? zoUGXO`b@nkl#1^$ehC6$i-QcXHu+m0-79wW>6gkhH(+NoHOtvrH3%6O%KfiP-vTDh zV-VR1{sTvY%MqMu00MBp9MJk%3t}7Px_Z$X=tJ0B@8d1SMcbn9ky}3ZmO?}lQH!+b z&{|K%`$O3}&-y|+K=eRca;Oh9z=kpuOrcOpNU@p)${|x*}P(gW$2x9aH9) z!I9^XT>)ll9E&EDRiAr8USlE0hl)(a4k}jc#_^FN71)oM)xZf<-U%ZV+zxPxt^;xG zx=6+?=A&TZLOJh zw%gii^|F(l?BssBoBgDH=OjUlk;826aOCPy?!#WL(8(3{E8X1eiKZBd_WVhj7*~7x zL`R?43%mN%OJypWIFYn0s71}Pmdz2NuHu*DSlejy2SrE+8?Nm>s4%a|6L2JSRtu|P za|VCgpe|VtKV7sDeZN6vAU2lUvV;u3K&aerz+@xh2)dAYqsFm)(Nm)8oFH#wbFawQKVdl+j2iaB=uSTNq+m*(}_0{rRK3r zq>(;q!?Q2`7SlzNIEUxm5=+V^+$^X#Q?w*i z@_E4wS|K%Lh1IYxb7n-17@`{G5f*UtCRdKE${>dg$&j!-8@w5)Xcf>(H!I221|A(n zMra%vVcbyjiQ$If){0BrG~8AvR9J`|sb=I*fs03SopeHCYNqN6k|@rxf(BfV<;rIbDl*!611+&%U-b0s9XQ&P?CnYnBzt%5 z^hs;7Ts?Q-WWmcg_O|1NdKc_rZe9e%7aATT%zx{v!%r8QtZtA&>0`C{-W`mrVT6_1ZwsO@ju9C? z*8nn(9H#fUH$m-XUR!kZxEuZO50r?RAd|VNF3B>Kq(mksv5Zh!MZwa!>cE?!(>5 zUhVX!ee4{u*NMuN>#L8wEmSxRuagf44FPgGJWx7~RNgb)G+#mwuCj8m4ia|rvb)CB zfh-0%j(dcnk5T6w>iiq+d5m^HLdug^cTrvlue~-_3bz-fh1kZK{B7~aBlEG3K_6UK r3a&2-&xI!LEO)i@Ib!qTR>X;4D4#12P|F-@nNHtFEq|i-eEj|gh*|uR literal 0 HcmV?d00001 diff --git a/Python-MySQL-Integration/model/UserModel.py b/Python-MySQL-Integration/model/UserModel.py new file mode 100644 index 0000000..4e71006 --- /dev/null +++ b/Python-MySQL-Integration/model/UserModel.py @@ -0,0 +1,16 @@ +from entity.User import SessionLocal + + +class UserModel: + @staticmethod + def save_user(user): + db = SessionLocal() + try: + db.add(user) + db.commit() + return "User saved successfully" + except Exception as e: + print(f"Failed to save user. Rolling back. Error: {e}") + db.rollback() + finally: + db.close() diff --git a/Python-MySQL-Integration/model/__pycache__/UserModel.cpython-312.pyc b/Python-MySQL-Integration/model/__pycache__/UserModel.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a85d3b2a37df9bdad823ea0b3729c69543854744 GIT binary patch literal 1133 zcmaJ=&rcIk5T5t83*E9+D8#15m^Bc!A`K?Q7-BF~$`7GLZ9LF4ZkF8ztJ^N@ZiOXa zJaC{9gEtPwcsBe4+zej5aPUAjnvm#0Zc#hVyKUsaBs)9v=9}-mnR)MHI2-~Z z-}8raZxO&(>i80<8`U0SY=Z&{(x8B{2myvMQ1Ch^%ntTYS!@U5><{Y1k;7+H)6DC| zDP5K{*+Y1`4u|SF;%|crS)@P~tBiuyVW*DF25cN>9PWXs8fjfoHJO~PAuO>N@>K`O z>NZ%7n4i9eI9NrGDdw20!cHBHD1tH_6Q2Wt%h7r)Oxz~IM%`cqeMAo!m)Ee>=KBg> z#joKF{%^;yA8r1dd^4oSYxo&12EG3hT7qR}29~^fPCg5C(~3^S_-t`zdL>GGE11$# zRT0dRER%W7l{C#>xiTu{HL_^wZd51{Ttc|7Yg)cIFU(5vlZ22m4BZ$M;;jblvBOA; z;$Q%pG-DDSskp*I!HAshad>G@sYvY z*hnUI{YEa6y4LS1p?;Cf++Evxq!;_rcIMtx-$c<;=M9O{=L+7&qSoPn?f8j9Y_!TiOT@K| zs1KVa18P%?R^GA`w0rK5J(e>R;{qvjEqK#A(U1`%E`3>Mgs2LG5c&c=zgu_|Jp!WK FoPS|9`}hC= literal 0 HcmV?d00001 diff --git a/Python-MySQL-Integration/static/js/index.js b/Python-MySQL-Integration/static/js/index.js new file mode 100644 index 0000000..cf578f5 --- /dev/null +++ b/Python-MySQL-Integration/static/js/index.js @@ -0,0 +1,29 @@ +function userRegistration() { + // Get form values + const name = document.getElementById('name').value; + const email = document.getElementById('email').value; + const password = document.getElementById('password').value; + + // Prepare the data to be sent + const data = new URLSearchParams(); + data.append('name', name); + data.append('email', email); + data.append('password', password); + + // Send POST request + fetch('http://127.0.0.1:5000/register', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: data.toString(), + }) + .then(response => response.text()) + .then(result => { + alert(result); + }) + .catch(error => { + console.error('Error:', error); + alert('Failed to register user'); + }); +} diff --git a/Python-MySQL-Integration/templates/index.html b/Python-MySQL-Integration/templates/index.html new file mode 100644 index 0000000..409b7ab --- /dev/null +++ b/Python-MySQL-Integration/templates/index.html @@ -0,0 +1,67 @@ + + + + + + + Python-MySQL Intergration + + + + + + +
+

User Registration

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