From bc619a54de11e8bc68f19f1ab4f13ec2da46542c Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Wed, 29 Nov 2023 21:20:59 -0800 Subject: [PATCH 1/8] changed the backend to accept a response body --- .DS_Store | Bin 6148 -> 6148 bytes .../src/__pycache__/database.cpython-311.pyc | Bin 694 -> 687 bytes .../src/__pycache__/models.cpython-311.pyc | Bin 1678 -> 1671 bytes .../src/api/__pycache__/info.cpython-311.pyc | Bin 2042 -> 2035 bytes .../src/api/__pycache__/login.cpython-311.pyc | Bin 183 -> 176 bytes .../api/__pycache__/server.cpython-311.pyc | Bin 2573 -> 2566 bytes .../api/__pycache__/settings.cpython-311.pyc | Bin 4091 -> 4084 bytes .../api/__pycache__/signup.cpython-311.pyc | Bin 2155 -> 2598 bytes .../api/__pycache__/workouts.cpython-311.pyc | Bin 186 -> 2528 bytes backend/src/api/signup.py | 19 +++++++-- react-frontend/src/components/Signup.js | 39 ++++++++++++++++-- 11 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.DS_Store b/.DS_Store index 8b10fb7f5949824371b01b7c80d8cb8f266d6f67..4b944dab2c97973466557ffb88c485de16431cc4 100644 GIT binary patch delta 48 zcmZoMXfc@JFUrQiz`)4BAi%&-!l28L#!$qN&ycrSkYhPBBirVEES}608#Zlb=lIJH E0PQOanE(I) delta 216 zcmZoMXfc@JFUrZlz`)4BAi%&7&ydTI&yd1U%8;{JkYhP>JxGd&ArCB=iY(2L%24c? zlb@WFlb-}s1Jujl2*i5-!2rl&U=U;|U`S+0X2=GT=|J_m3^_n^Kzu!hEQVqrI}go- f^=KyWXrLK^LnEW?WE&Qp%{nZa%$wOc{_+C=hx;;K diff --git a/backend/src/__pycache__/database.cpython-311.pyc b/backend/src/__pycache__/database.cpython-311.pyc index a91b43545e865b7ff764b69677486ec7f1489ec4..09fdee8622b80eb1e6255a82c5d271efbd151b3c 100644 GIT binary patch delta 54 zcmdnSx}KGLIWI340}w>~Oy9`u!zkmVA6lGRRIHy>SelxZsGppeQ;?rinOv-&T%5eQ IiqVD<0JFFeApigX delta 61 zcmZ3_x{Z~4IWI340}yzbq;BN)VN~|i4=qkDD%LMZEGo`O%u6gz&CbZr(|1WN&MwI> P(02}Yj^A9&Xu}8q6#5dl diff --git a/backend/src/__pycache__/models.cpython-311.pyc b/backend/src/__pycache__/models.cpython-311.pyc index b9c41d1a3fe7f39547967fe55ccf16f802539ef9..5204a118c81e4269a676be35f2a1095085257eda 100644 GIT binary patch delta 54 zcmeC~(>HRTWtMT!4=qkDD%Q^`EKSWy)K5;#Dag;MOfJ?>E>7P3 In|U%50J}*NJpcdz delta 61 zcmZqY?c?QM&dbZi00dqpsT;Y^GAq05hZd(673&uy78PeC<|P)VW@qH*>AR#BXP4v` P=sO2H$8Y|^Jedgq9#Rw3 diff --git a/backend/src/api/__pycache__/info.cpython-311.pyc b/backend/src/api/__pycache__/info.cpython-311.pyc index 67f6c028a5700a84c6b4685a3d2c1d8ebfa4e569..370a85309e2c9a61a88d6e66a5c5d6e26aae3dfd 100644 GIT binary patch delta 54 zcmeyx|CyhAIWI340}w>~Oy9`uz$D|OA6lGRRIHy>SelxZsGppeQ;?rinOv-&T%5c) IkEw?h0MgnK`v3p{ delta 61 zcmey&|BIh{IWI340}yzbq;BMPU{dzf4=qkDD%LMZEGo`O%u6gz&CbZr(|1WN&MwI> P(02}Yj^CWl)WZq@I1>|+ diff --git a/backend/src/api/__pycache__/login.cpython-311.pyc b/backend/src/api/__pycache__/login.cpython-311.pyc index 7e77511ed2f43009919f079b404a4c5e397d7a58..a6f6aa3170f67bd4b2c54beed59db5bc04fa5a2f 100644 GIT binary patch delta 51 zcmdnaxPg&-IWI340}w>~OrOYYD&wplTAW%`te;g_nwpiUpPZOeke^eTT&$m5oIEi( F1OS7x5WxTd delta 58 zcmdnMxSf%EIWI340}yzbq)y~ERrb;kElw>e)-OmbD$YpEODs;!&dATxcS$YIF3B&@ McMf)rpBNJY0N~;hSO5S3 diff --git a/backend/src/api/__pycache__/server.cpython-311.pyc b/backend/src/api/__pycache__/server.cpython-311.pyc index b9de87c23e130b6e05f6384625c617cf02d0b521..1ce6f36ace6744788a9f4352836990849d386750 100644 GIT binary patch delta 54 zcmeAbX%pdI&dbZi00a>~(>HRrvdXyVhZd(673*gemZoMU>L(}W6y)brCKu}`7bkDt I%o@c40J7H+iU0rr delta 61 zcmZn@=@sE#&dbZi00iv*sT;XlS(Ux@LyJ?3iuDT;i;6Q6^Ad|wvorGZ^j%VmvrF;| P^qqs9<2SEijbZ@+49gPv diff --git a/backend/src/api/__pycache__/settings.cpython-311.pyc b/backend/src/api/__pycache__/settings.cpython-311.pyc index 96b3cdb8ecc83e1fd5000a49a1a60a6ddd4573a2..341a3e806a02c8e58b8303788f71581680f6ae9b 100644 GIT binary patch delta 53 zcmew@|3#jAIWI340}w>~Okc>&EaRphTAW%`te;g_nwpiUpPZOeke^eTT&$m5oV;0& H`793r$uAMx delta 60 zcmew&|687WIWI340}v#cq%GuTR`%5oElw>e)-OmbD$YpEODs;!&dATxcS$YIF3B&@ OcMf)r->lAjmInYbvlEK| diff --git a/backend/src/api/__pycache__/signup.cpython-311.pyc b/backend/src/api/__pycache__/signup.cpython-311.pyc index 2457128e6dc0b74cd7d1483f811d3b4d23657f83..9281cd95ecc2d5bcecc755a1176bb4828c779b62 100644 GIT binary patch delta 1421 zcmZWp&2Jk;6n`_j-nAV&wrj^unl`o6w2?u`5LeT2XK)k%pQ8_k&B}QA@$TZw%3Wv^UiO6?_=J~ z+j;AM;;q!ePtj-?P#&jmvcF}3=R)x%FeLkp`wR8sCYWj^zL_W`2(W1Rm>;#9y#MUX z-PE|rcOIS1P>TRO!ZDE26a^MzDK^!jXvZ`ipCho~C41F{TFU`1Lkw!E}ywI|4v&&VJRa{D! z){RjJlKzf3@1IBb0T`5s2_mD7jD*s*4zS=hnREbuu$(-)Dv(J$$ZI&SW%d{C7^+#Q-CCHH%Ju2lBl9yFkg z9XAk@Jf!1Sv`reM>~|oP6+d#DI+H#JCYx<|yU7oDhotvI&Z>(Edz1EN6QyA#}DlgvUqs6%Z&x++ii`~{l zZay#6uu-)vW{7+D6wd5=#j(Zv>K}@q5+M_V+ZZf5hnAB#?Ees&@UH^#>2J6Hip~ES zo9`y3JBicX)NCh}>jk8 z;>Zf^0Yonj(WT0IGPAUtm7Zkf<$3kV0zu3jcN@ywN**`ossM3wo@8@_hlKjNP!+T4 zFzXfUR{YCJ?;Iny~ zzk{my)3G-YdlDg}>*m$0`;oep>B3xl{OKv6hTPxPwTeuVJ@`NT7}^uogF{yYXz=UV jFK55G@synCkP|(cB=PplYdygE5cVXXCw=#!xqs%DBWyB2 delta 1033 zcmZ8gO-vI(6rTNIcl%#x1tO@8K!6ymksxYN38;~fK$MyiOsGqDpnvYx* z2QOqUMmaPdY78Dcc~(x`EQUn02SZ{!dBG4b#Dg=XEiEte-kW*zeednOnJol=`@7$I zJWfF5*ARqPcmRIVMMWIt$^OH&ZgT{BQvS+LzOgc^^@>$1$M%9Sm_JcL)_TQVUr_PDX2na?N7N6S=Ov}_DPJIz zjWUfKai#^oVJv)(z2;qVhvNv!2JAC+i0~KoVoRJLszMvU5#8^>9=`v!#VE`=TVFEA zTYQRQN|LIwa}7qRvE{f>27tVXU-4ZJ1WU+El~}De0!OP~v0k|;l-5imnn*5% z=j3=A;zcfa!*(6s-C@BVl9#>_eVdpS@K*r-))%>NzRs_{&JWHlPq8aX#f@wb07^p(iAfT zucJ$3Nq-!DnAkmzVVLjuvlPNVq{rN@AmMpOBnnvRS=(yc^Vw~teTQk^WBrW(<>($D d?gLkHp8_RUyc;R`BlCv??5PUpD2xV3$^W+$+t>gA diff --git a/backend/src/api/__pycache__/workouts.cpython-311.pyc b/backend/src/api/__pycache__/workouts.cpython-311.pyc index ba444f5577722a0f4a87a14770715cb7495e891e..702c41dc7c2d50ca0611bce684dac6087eac4767 100644 GIT binary patch literal 2528 zcma)7-ER{|5a0Xo`OcrjNlfifVwxi2%Eh!$p;myDLQ;qzM)?rMc{p8sYv;oGZ0^p= zM?>Wz)J7Fjc|d}PR!u9Ks)GIz{0B}Isi%FaRPoR^M?os(rJX(doH#{l=k{jjH@iE# zH#;-;V>lc@Kp+2A!teSJ`kexg0K2r)fbIcOk;>?(%;cFen`g^ho-6Zto}qeH_mzdb z;L4otFN=B6m3dvtOEB)!1La^oC z?jSXY#SIR|;BAi`z|r*{5AE&M&;|oD;cbx`#<3!+M(*$%pm^-5QNCB@r%*cj2i2r` zB8^>@k=0F274>DenvWpe-23WU<=t*go2vrjowI#yaO35m8js}AFp*tpk z2MD7)qoO=J1J2KLn8!YqJp&_v1Q&5_$S!f$(IUg3>xhA8m8}oh^s?Gy(klesIdMXO7F?c(U< zsJBzZ6&3f zg}X^fbCd|J6Q*N?Rp*F+jgn?y;+wN4SqSeDJ8e0WE1&)>4ytW&%m!eL%;M4{V@J0 z*JSzdfo)DW8hDO?HA5&Izqi;34sM5q*b&ghj{F%yZyfu+|GR^a4mQI`iZ(egcn2V|F#qDzq_(eYW7GWp@~||Cs;I=zdbuL%sn0EM>77WSq6BzkNAsF z|DkM})RVjSWzzg6J?+8c;BEK!XqkSh7pu#vV%S>26zQsAs^g&knlwwzH{B`pUukP) zY|_jmg6aN_-C9hz61EAa8Mb>x<{`SsEsgXRUy5g1Kb3RlX@IoWSsd^t$1se8&Nlw5 zIq0oMcXQC;Mt5^iPs3}k8cj4%SNlzhttFgb+zIrp9cucx0K1KVJ*TWLGy{Hy#?!yp xz4sv=m?Xr5Hxxsx_(k$|a_#aalh|SsP4*xoJUrP%(CxBq4zWpZbXV;<=^sfFSkM3f delta 153 zcmaDLyo)h;IWI340}yzbq^5%C#~=a*7@>^MY(U0zh7^Wi22Do4l?+8pK>lZt { + const handleSubmit = async (e) => { e.preventDefault(); + // Check if the password and confirm password match if (formData.password !== formData.confirmPassword) { setPasswordMatchError(true); return; } - // Handle form submission logic here - console.log("Form data submitted:", formData); - navigate("/info"); + + try { + const response = await fetch( + "http://127.0.0.1:8000/signup/create-user", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + user_email: formData.email, + user_password: formData.password, + first_name: formData.firstName, + last_name: formData.lastName, + }), + } + ); + + if (!response.ok) { + // Handle error cases, e.g., show an error message + console.error( + "Failed to create user:", + response.statusText + ); + return; + } + + // Handle success cases, e.g., navigate to the next page + console.log("User created successfully"); + navigate("/info"); + } catch (error) { + console.error("An error occurred:", error); + } }; return ( From 241ff66a213100727ebd992709fbd3af154db44e Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Wed, 29 Nov 2023 21:45:55 -0800 Subject: [PATCH 2/8] added pop up for user that is already registered --- .../api/__pycache__/signup.cpython-311.pyc | Bin 2598 -> 4069 bytes backend/src/api/signup.py | 35 +++++++++++++++++- react-frontend/src/components/Signup.js | 21 +++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/backend/src/api/__pycache__/signup.cpython-311.pyc b/backend/src/api/__pycache__/signup.cpython-311.pyc index 9281cd95ecc2d5bcecc755a1176bb4828c779b62..80627b8308501d5f69f85acb4b23dd0a5b07fe3b 100644 GIT binary patch literal 4069 zcmcf^U27ZJ_0ET8Mqid?D~>;sSj1_&3Qm-eEosB1;7#P%O(GdPZiou2jy2czD5H^b zXSDvnhH(h2DS?JkNFEl}Pie~LM|9bJ*he|2L=2P$N(%cnCSC~p)N@A~OA}{l`_j?O znRCxM_sqHH-t(b9N24JGmv&+qUy%^{CmncKppCrw7lY7aq#%XSP?^ayWj4>2xja|q z^E^Z8tQIH>d7&)kMR&|;fqVeyye5@{`H)KsXyI}sA8~O(irSoTFe{ z91q~5Pg&3fPg_?n&>1DHM3$K6(RX-*EV_o2o(D*Y;r^!_%!8*rZ^-5K0xy1uH;e~& zMm)*xx6#7(!27+HKlY;pRwX*jNMb0~H6JNo$)ZwDu4re`ZP z6BApU#rJC1Fzx8nty?ph)grE%YDKpN!<5aMkz(y=kzm=x1*|WrI<|QeubSBuV@rx` z$_uiA0S{{xSt%$L6YHPCF!JlUTy_>4)r#)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u@`m>zl(;-w&Y3;LgyqYxU%Ze;uobCwIe>jqqfhpEPKy`QqHf2=~)2 z_1NXBpn{MB>fHy0Ry>%p|FC}&it`@SkkD74+yiK#SG;6hb?bBLge@*Y%LWY-p^6Dl0gV_!KS5}-MChq?BMX`} zQY5s9k_!MJ^|)!9^AhCr2k2AH+-@YK50p>f_>XV&2XX_>f0WM z01L4YTOk%=E5urY6XBVD2OS1af_sz-5#;eB0uy!6VX(cnN2&WARxe_u&qnT#Y=5%L z9BVMg9QG&7HKsmv+CdcQhI<@hj~|FQGw>(5HTAc<%us_Fa#)55K3aAVygGo+8uqvy IvU`UA4PhCifB*mh delta 959 zcmZWoJ#5oJ6uvt0MrU=TU=~e^s8+M;v0@A(>Fc$4JyA?x#LQ|El0dq{-cBf$r$!GW zv?+C8imCreoiB+yX@XdcrC7R0BwgwO-ID8=hG}F8zl|QlG6Y>i)LcW&4Zp+R1+C zJq^uhMY*3>$eYv8-EE`lVOQy^K|P8$$YA3Y+{V>VfLFD^TOqC$_y|>v!0!&p`A>zE zw$cs5PVT$e0Ftz5;L~Gm+C+|F2B`E8i~l<+RW{VY<6Kd_J$+iIsyu|yP49=XHJ6c9 zI5g!cX?$|)dLiZ;qSdq?*n;`0-EzymE-FjTLaW*5@H7zBmSEf`73zH)nx=>~L+GCvhW#sm0hx!>e3M@ha5 diff --git a/backend/src/api/signup.py b/backend/src/api/signup.py index 00bf35e..f946041 100644 --- a/backend/src/api/signup.py +++ b/backend/src/api/signup.py @@ -3,6 +3,8 @@ import sqlalchemy from src import database as db from dotenv import load_dotenv +from fastapi.responses import JSONResponse + load_dotenv() import os @@ -26,9 +28,34 @@ class CreateUserRequest(BaseModel): first_name: str last_name: str +class UserInfo(BaseModel): + uuid: str + weight: int + height: int + Age: int + gender: str + dob: str + @router.post("/create-user") def create_user(request: CreateUserRequest): + with db.engine.begin() as connection: + existing_user_result = connection.execute( + sqlalchemy.text( + """ + SELECT id + FROM users + WHERE email = :user_email + """), + {"user_email": request.user_email} + ) + + existing_user = existing_user_result.fetchone() + + if existing_user: + # If the email exists, raise an HTTPException with a 400 status code and error message + raise HTTPException(status_code=400, detail="Email already registered") + new_user = supabase.auth.sign_up({ "email": request.user_email, "password": request.user_password @@ -46,4 +73,10 @@ def create_user(request: CreateUserRequest): {"user_id": user_id, "first_name": request.first_name, "last_name": request.last_name, "user_email": request.user_email} ) - return "OK" \ No newline at end of file + # Return the user_id in the response + return JSONResponse(content={"user_id": user_id}, status_code=200) + + +@router.post("/add-info") +def add_info(request: UserInfo): + pass \ No newline at end of file diff --git a/react-frontend/src/components/Signup.js b/react-frontend/src/components/Signup.js index 6498f7f..f244575 100644 --- a/react-frontend/src/components/Signup.js +++ b/react-frontend/src/components/Signup.js @@ -59,12 +59,33 @@ function Signup() { } ); + console.log("Backend Response:", response); // Log the entire response + if (!response.ok) { // Handle error cases, e.g., show an error message console.error( "Failed to create user:", response.statusText ); + + try { + // Attempt to read the response body + const responseBody = await response.json(); + if ( + response.status === 400 && + responseBody.detail === "Email already registered" + ) { + console.log("Alert should show up here"); + // Use alert to show a pop-up message + alert( + "Email is already registered. Please use a different email." + ); + } + } catch (error) { + // Handle JSON parsing error + console.error("Error parsing JSON response:", error); + } + return; } From 1802bb3d1cc417adbf3f7cd9d7d8c98b6118220d Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Wed, 29 Nov 2023 22:33:48 -0800 Subject: [PATCH 3/8] added the add_info end point, working --- .../api/__pycache__/signup.cpython-311.pyc | Bin 4069 -> 4857 bytes backend/src/api/signup.py | 21 +++++++++++++++--- react-frontend/src/components/Info.js | 18 +++++++++------ react-frontend/src/components/Signup.js | 14 +++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/backend/src/api/__pycache__/signup.cpython-311.pyc b/backend/src/api/__pycache__/signup.cpython-311.pyc index 80627b8308501d5f69f85acb4b23dd0a5b07fe3b..2e43e8728dd7f1e5f65149d0bc0e3ec2ad963990 100644 GIT binary patch delta 1591 zcmZvcOK%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Mg0PF0yEPyX8yNH=Tw@IAM~H2DJ+^sNFYoC{CE#w zDXza%tJXR6F(KW+G~|bkiJ>IK;7D*dS1B{mrgtOBFUIA4;|iUWuZ(mmhq>J)!I$cM z5h-F8JY%ho#(=VbPYo~rw-4YsJWv=Lo%hacQ85lq8&h&32k7ccj4hU7oZ<$UcR*}E zfJ44$x^vwdl9iR2Xf|^J+yY}l2XIweltci{X<3L`rc$%TMKpsL)i<`-Qng+#iI98~ z9l7M)G|t)8Hfna=>(|@y%w7D|XVzk diff --git a/backend/src/api/signup.py b/backend/src/api/signup.py index f946041..18db5b4 100644 --- a/backend/src/api/signup.py +++ b/backend/src/api/signup.py @@ -4,6 +4,7 @@ from src import database as db from dotenv import load_dotenv from fastapi.responses import JSONResponse +from uuid import UUID load_dotenv() @@ -29,10 +30,10 @@ class CreateUserRequest(BaseModel): last_name: str class UserInfo(BaseModel): - uuid: str + id: UUID weight: int height: int - Age: int + age: int gender: str dob: str @@ -79,4 +80,18 @@ def create_user(request: CreateUserRequest): @router.post("/add-info") def add_info(request: UserInfo): - pass \ No newline at end of file + + + with db.engine.begin() as connection: + result = connection.execute( + sqlalchemy.text( + """ + UPDATE users + SET weight = :weight, height = :height, age = :age, gender = :gender, dob = :dob + WHERE id = :user_id + """), + {"user_id": request.id, "weight": request.weight, "height": request.height, "age": request.age, + "gender": request.gender, "dob": request.dob} + ) + + return "OK" \ No newline at end of file diff --git a/react-frontend/src/components/Info.js b/react-frontend/src/components/Info.js index 96b080b..fca4bac 100644 --- a/react-frontend/src/components/Info.js +++ b/react-frontend/src/components/Info.js @@ -1,6 +1,7 @@ import React, { useState } from "react"; import "./Info.scss"; // Import your CSS file import { useNavigate } from "react-router-dom"; +import { useLocation } from "react-router-dom"; function Info() { const navigate = useNavigate(); @@ -36,13 +37,16 @@ function Info() { e.preventDefault(); try { - const response = await fetch("http://localhost:3000/signup", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(formData), - }); + const response = await fetch( + "http://localhost:3000/signup/add-info", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(formData), + } + ); if (response.ok) { console.log("Form data submitted successfully"); diff --git a/react-frontend/src/components/Signup.js b/react-frontend/src/components/Signup.js index f244575..174620c 100644 --- a/react-frontend/src/components/Signup.js +++ b/react-frontend/src/components/Signup.js @@ -33,6 +33,8 @@ function Signup() { const navigate = useNavigate(); + // ... (previous code) + const handleSubmit = async (e) => { e.preventDefault(); @@ -59,8 +61,6 @@ function Signup() { } ); - console.log("Backend Response:", response); // Log the entire response - if (!response.ok) { // Handle error cases, e.g., show an error message console.error( @@ -69,13 +69,11 @@ function Signup() { ); try { - // Attempt to read the response body const responseBody = await response.json(); if ( response.status === 400 && responseBody.detail === "Email already registered" ) { - console.log("Alert should show up here"); // Use alert to show a pop-up message alert( "Email is already registered. Please use a different email." @@ -90,13 +88,17 @@ function Signup() { } // Handle success cases, e.g., navigate to the next page - console.log("User created successfully"); - navigate("/info"); + const responseData = await response.json(); + const userId = responseData.user_id; + console.log("User created successfully with ID:", userId); + navigate("/info", { state: { userId } }); } catch (error) { console.error("An error occurred:", error); } }; + // ... (remaining code) + return (
From 54d70a9755dd41678a36883354b69fcbd647cb61 Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Wed, 29 Nov 2023 23:11:28 -0800 Subject: [PATCH 4/8] not done yet with the add_info, body of api call needs to be worked on --- .../api/__pycache__/signup.cpython-311.pyc | Bin 4857 -> 4907 bytes backend/src/api/signup.py | 2 ++ react-frontend/src/components/Info.js | 31 ++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/backend/src/api/__pycache__/signup.cpython-311.pyc b/backend/src/api/__pycache__/signup.cpython-311.pyc index 2e43e8728dd7f1e5f65149d0bc0e3ec2ad963990..8c5622d1fd6d5a18ef5e2970c2b08953c7dab613 100644 GIT binary patch delta 261 zcmeyVx>}8QIWI340}x!&&q(#!$oquHN{f+!VLC$zkc5F6hGjtBYPbj^LkSa1j)5Ty z&Ymp5CN}vGt0*JOWJY#jeuffmBvovaqj{w#H}P7s)G%c6Y~IW(&B(!fi?yIAGp}Uw zdA?LRcc9`xATB-&BpMjLvN5o7b*MM`wfHsoePx^M%70LBog<$U2lF8g7AGF|L;Q?R zJd?!*4l=q=z9}Hf7`pkpz$HclK}LZI86Oyc6oUB3%)lgdg;DYY6N+$=0?;A={BbrM delta 155 zcmZ3j_EVL2IWI340}!m%$w)QZ$oqtciHC9W8P*1t8ip*k$(_6|n{V<8Gcxi_{=%0k z=mu062*kw)fJ6hsSB}Z${09Z+JMuYNG9R>LakOPW#K7oiJK0m { const { name, value } = e.target; @@ -36,15 +39,39 @@ function Info() { const handleSubmit = async (e) => { e.preventDefault(); + const formattedUserId = `"${userId}"`; + + // Convert weight, height, and age to numbers + const weight = parseInt(formData.weight); + const height = parseInt(formData.height); + const age = parseInt(formData.age); + + // Log the request body before sending the request + console.log("Request Body:", { + user_id: formattedUserId, + weight: weight, + height: height, + age: age, + gender: formData.gender, + dob: formData.dob, + }); + try { const response = await fetch( - "http://localhost:3000/signup/add-info", + "http://127.0.0.1:8000/signup/add-info", { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify(formData), + body: JSON.stringify({ + id: formattedUserId, + weight: weight, + height: height, + age: age, + gender: formData.gender, + dob: formData.dob, + }), } ); From b82cd0ae5e9004989febfd698acf30b8a099db30 Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Thu, 30 Nov 2023 12:47:02 -0800 Subject: [PATCH 5/8] got the sign up to work --- react-frontend/src/components/Info.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/react-frontend/src/components/Info.js b/react-frontend/src/components/Info.js index 9dbe7c2..bea0dbf 100644 --- a/react-frontend/src/components/Info.js +++ b/react-frontend/src/components/Info.js @@ -39,22 +39,26 @@ function Info() { const handleSubmit = async (e) => { e.preventDefault(); - const formattedUserId = `"${userId}"`; + const formattedUserId = `"${userId}"`.replace(/"/g, ""); + + // Log the request body before sending the request // Convert weight, height, and age to numbers - const weight = parseInt(formData.weight); - const height = parseInt(formData.height); - const age = parseInt(formData.age); + const weight = parseInt(formData.weight, 10); + const height = parseInt(formData.height, 10); + const age = parseInt(formData.age, 10); // Log the request body before sending the request - console.log("Request Body:", { - user_id: formattedUserId, + const requestBody = { + id: formattedUserId, weight: weight, height: height, age: age, gender: formData.gender, dob: formData.dob, - }); + }; + + console.log("Request Body:", requestBody); try { const response = await fetch( @@ -66,9 +70,9 @@ function Info() { }, body: JSON.stringify({ id: formattedUserId, - weight: weight, - height: height, - age: age, + weight: parseInt(formData.weight, 10), // Corrected the typo + height: parseInt(formData.height, 10), // Convert height to an integer + age: parseInt(formData.age, 10), // Convert age to an integer gender: formData.gender, dob: formData.dob, }), From 74a28a8d72e2cb8b7384845d8ec1699c0d024c17 Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Thu, 30 Nov 2023 20:28:08 -0800 Subject: [PATCH 6/8] finished the end point for login --- .../src/api/__pycache__/login.cpython-311.pyc | Bin 176 -> 2452 bytes .../api/__pycache__/server.cpython-311.pyc | Bin 2566 -> 2640 bytes .../api/__pycache__/signup.cpython-311.pyc | Bin 4907 -> 4907 bytes backend/src/api/login.py | 48 ++++++++++++++++++ backend/src/api/server.py | 2 +- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/backend/src/api/__pycache__/login.cpython-311.pyc b/backend/src/api/__pycache__/login.cpython-311.pyc index a6f6aa3170f67bd4b2c54beed59db5bc04fa5a2f..b4bcd536bf48a3c59389ae7d67d74e3ba083b254 100644 GIT binary patch literal 2452 zcma(ST~8EO^v=i5ezWYZD2NJ0s$G-1rY7oxHUVo|s4fT+%cSXKn0tl6*_rjuEMI|U zB_#4_6BB*t15Z>VP5cSkr#=qNCf!V8LeliXw>8+r_|$U;26x4zy?f@|^L5X?oG*S! zCSwTJ_uuK{cnG1t7!xeu{k8poL+ByG2y+H1axz!sWxgoLLQ#}Oj>&l=RFq_?7?#66 zFBl;?1ai@c6r*y?mxYXYF(D^>S~8Nw7P-Zz!$zvuDz|coMFI-k`P!j?YTR*b9bW$wzMUnv|Bo~A56*PJ+p?scbgc8> z3%*@n8IW^0fs>QmM#~4f!#w&L;nWJkt)y*TfOGKep6eus*Ny~SV-$hoiecRL$4CGB64$ zs=DDNeY&LD_N+y5As6x@iejooq9|TWQHmBW8;njU%AK-m>}mwtpi^MAJbE7%c`m%>B$a7wZzY$V~@B15HbTqYd!l7K@__PuOTXufd<(X_(?x4W=}!yA!izsp>c zMHI*OTVS*#{3y(FvuI8jN3&cmUVxem?G#KTs1+~lmyV8K{SNnmL0Gd)Xb{JX@AQ_U zLE$fS445;jq2q49w!5L(Fxcp-Ve3CZtQWF@zCn}Y>1W{6lQ40hNcA_&ux$XmQ&Tm% zp}J-W?Ix63G#B?GcDdv?swb*tXUc1{^+{9FO=VVhrj+2hlubs;hN363hkLw^X`Hdq zy{SMunGMTXPNbhOU4-s-IsKHe9I;u(yJ68TCW!femBJj-FF?SG&wd7|g6dK#be(&d z?R;?Q&+NHBvge+ktoGkJkF0&#Rf9)$l(OYCW zg=(hYCJNv*+s&jyZf1BhGhEFKyNThqu+9=+Tb>r0{+$yk3%cyZ`#e@yr- z76LkV%nRRAA*&^wvg)TS2!5O>D{C)i-!W7}nu1w!Em(BY> zY)ZXVskb83q{u!|ynXf3qwFJXGu~5;_f#TV(adT`EuO8#(yJZykPzcvBS3E$sz~)1 z&mF3x{pkMqYbJg3UKK-p~Oiu;Tk3j?sFhUuh*?^4c3@Hr344RC7D;bKI7#JqoGkfd& k;;_lhPbtkwwJTx;Dgmi4<_8iVm>C%vKQO?EB4(f%04~xJ(*OVf diff --git a/backend/src/api/__pycache__/server.cpython-311.pyc b/backend/src/api/__pycache__/server.cpython-311.pyc index 1ce6f36ace6744788a9f4352836990849d386750..b8655eb309d6636757f66c4c2ca575a6725dedf8 100644 GIT binary patch delta 76 zcmZn@xgf&3oR^o20SH_}GgFsO~rl+o)$ScY8jd7!fBID*-MizF)4V#-dG#D8lOg_lj4*)UT B4d?&> diff --git a/backend/src/api/__pycache__/signup.cpython-311.pyc b/backend/src/api/__pycache__/signup.cpython-311.pyc index 8c5622d1fd6d5a18ef5e2970c2b08953c7dab613..bae71609f33a3f14eca726e4f7e57a09fc2f9084 100644 GIT binary patch delta 20 acmZ3jwpxvQIWI340}%WT$=t}TAPfLGMg<}O delta 20 acmZ3jwpxvQIWI340}x!&&)CSVAPfLEHU!ZC diff --git a/backend/src/api/login.py b/backend/src/api/login.py index e69de29..3fe880b 100644 --- a/backend/src/api/login.py +++ b/backend/src/api/login.py @@ -0,0 +1,48 @@ +from fastapi import APIRouter, Request, HTTPException, status +from sqlalchemy import create_engine, text +import sqlalchemy +from src import database as db +from dotenv import load_dotenv +from fastapi.responses import JSONResponse +from uuid import UUID + +load_dotenv() + +import os +from supabase import create_client +from pydantic import BaseModel + + +url = os.environ.get("SUPABASE_URL") +key = os.environ.get("SUPABASE_KEY") +supabase = create_client(url, key) + +router = APIRouter( + prefix="/login", + tags=["login"], +) + +class LogUserRequest(BaseModel): + user_email: str + user_password: str + + +@router.post("") +def login_user(request: LogUserRequest): + + try: + response = supabase.auth.sign_in_with_password({ "email": request.user_email, "password": request.user_password }) + + + user_id = response.user.id + + # Return the user_id in the response + return JSONResponse(content={"user_id": user_id}, status_code=200) + + except Exception as e: + # Check if the error is due to invalid credentials + if "Invalid login credentials" in str(e): + raise HTTPException(status_code=401, detail="Invalid credentials") + else: + # Handle other AuthApiError cases as needed + raise HTTPException(status_code=500, detail="Internal server error") \ No newline at end of file diff --git a/backend/src/api/server.py b/backend/src/api/server.py index c75fb3b..c53c91a 100644 --- a/backend/src/api/server.py +++ b/backend/src/api/server.py @@ -33,7 +33,7 @@ ) app.include_router(settings.router) -# app.include_router(login.router) +app.include_router(login.router) app.include_router(signup.router) # app.include_router(info.router) # app.include_router(workouts.router) From 004846ad72009f5dbfe8637f6892511021332598 Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Fri, 1 Dec 2023 15:20:29 -0800 Subject: [PATCH 7/8] added the log in page --- react-frontend/src/components/Login.js | 53 ++++++++++++++++---------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/react-frontend/src/components/Login.js b/react-frontend/src/components/Login.js index 7cd4ac1..8b013db 100644 --- a/react-frontend/src/components/Login.js +++ b/react-frontend/src/components/Login.js @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import "./Login.scss"; // Import your CSS file -import supabase from "./Supabase"; +//import supabase from "./Supabase"; import { useUser } from "../UserContext"; /* eslint-disable react/no-unescaped-entities */ @@ -23,29 +23,42 @@ function Login() { }; const handleLogin = async () => { + console.log(email); + console.log(password); try { - let { data: login, error } = await supabase - .from("login") - .select("*") - .eq("email", email) - .eq("password", password); - - if (error) { - console.error("Error fetching data:", error.message); - } else { - if (login.length === 0) { - console.log("No match found."); - // Handle no match found case - } else { - setUserId(login[0].id); - console.log("Current userId:", userId); - // Handle successful login, e.g., redirect to a dashboard - // Use history to navigate to the settings page - navigate("/"); - } + const response = await fetch("http://127.0.0.1:8000/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + user_email: email, + user_password: password, + }), + }); + + if (!response.ok) { + console.error("Error during login:", response.statusText); + // Show an alert for login failure + alert("Login failed. Please check your credentials."); + return; } + + const data = await response.json(); + const user_id = data.user_id; + + setUserId(user_id); + + console.log("Current user_id:", user_id); + + // Pass the userId using the state object in the navigate function + navigate("/", { state: { userId } }); } catch (error) { console.error("Error during login:", error.message); + // Show an alert for other errors + alert( + "An unexpected error occurred during login. Please try again." + ); } }; From 50ca232e4c61b1b86d5887e518ea9e35857add19 Mon Sep 17 00:00:00 2001 From: Josh Queja Date: Fri, 1 Dec 2023 15:27:37 -0800 Subject: [PATCH 8/8] fixed the server.py --- backend/src/api/server.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/api/server.py b/backend/src/api/server.py index 7933762..c2a1df8 100644 --- a/backend/src/api/server.py +++ b/backend/src/api/server.py @@ -34,12 +34,9 @@ app.include_router(settings.router) -<<<<<<< HEAD app.include_router(login.router) -======= # app.include_router(login.router) # app.include_router(login.router) ->>>>>>> 67641a844335d6e0e7c7ebd0059bf8d862101dcb app.include_router(signup.router) # app.include_router(info.router) app.include_router(workouts.router)