From 107e6277c7c87869acc247e2019f0f77b0d27486 Mon Sep 17 00:00:00 2001 From: Jeremiah Robert Date: Fri, 1 Nov 2024 14:56:46 -0400 Subject: [PATCH 1/3] main code --- Sprint 1/UserLogon.py | 0 Sprint 1/Usertest.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Sprint 1/UserLogon.py create mode 100644 Sprint 1/Usertest.py diff --git a/Sprint 1/UserLogon.py b/Sprint 1/UserLogon.py new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 1/Usertest.py b/Sprint 1/Usertest.py new file mode 100644 index 000000000..e69de29bb From 3d935177cd3ffc04b35b3d0872cab4b6df731a93 Mon Sep 17 00:00:00 2001 From: Jeremiah Robert Date: Fri, 1 Nov 2024 14:58:58 -0400 Subject: [PATCH 2/3] updated code The main code and test code --- Sprint 1/UserLogon.py | 173 ++++++++++++++++++++++++++++++++++++++++++ Sprint 1/Usertest.py | 59 ++++++++++++++ 2 files changed, 232 insertions(+) diff --git a/Sprint 1/UserLogon.py b/Sprint 1/UserLogon.py index e69de29bb..7300ab1fb 100644 --- a/Sprint 1/UserLogon.py +++ b/Sprint 1/UserLogon.py @@ -0,0 +1,173 @@ +from dataclasses import dataclass +from xmlrpc.client import Boolean + +@dataclass +class UserInfo: + firstName: str + lastName: str + email: str + password: str + phoneNumber: str + SSN: str + symptom_list: list + insurance: bool + + + # add fields for the other info listed in activity 2. add input for create_account + + +class UserLogin: + def __init__(self) -> None: + self.UserArray = [] # holds UserInfo objects + self.loggedinUser = None # holds Single UserInfo object + + + def isInDataBase(self, x, field) -> Boolean: #checks if x is in field of the UserArray (ex if abc is already in the username field) + + for user in self.UserArray: + if(getattr(user, field) == x): #getattr is built in to python and it takes an object and a string that is a field of the object as parameters + return(True) + + return(False) + + + def login(self) -> bool: + """ + Returns true if login was successful, else false + """ + email = input("Enter the email you have an account with: ") + password = input("Enter your password: ") + for user in self.UserArray: + if (user.email == email): + if(user.password == password): + self.loggedinUser = user + print("Login Successful!") + return True + print("No Login found, try again") + return False + + + def create_account(self): # max entry length needs to be added, ex max 9 chars for ssn. should be in the second activity + + while(True): + firstName = input("Enter your first name: ") + + if(firstName == "cancel"): + return() + if(len(firstName) <= 50): + break + print("Please enter a name with less than 50 characters") + + + while(True): + lastName = input("Enter your last name: ") + + if(lastName == "cancel"): + return() + if(len(lastName) <= 50): + break + print("Please enter a name with less than 50 characters") + + + while(True): #makes sure a valid email is entered + email = input("Enter your email address: ") + + if(email == "cancel"): + return() + if(len(email) > 50): + print("Please enter an email address with less than 50 characters") + continue + if(not ("@" in email)): #if @ is not in the input, do not allow the input + print("Please enter a valid email! (Must include @) \n") + continue + if(self.isInDataBase(email, "email")): #if input is already a registered email, do not allow the input + print("There is already an account with this email!") + continue + break + + + while(True): + password = input("Enter your password: ") + + if(password == "cancel"): + return() + if(len(password) <= 50): + break + print("Please enter a password with less than 50 characters") + + + while(True): + phoneNumber = input("Enter your phone number: ") + + if(phoneNumber == "cancel"): + return() + if(self.isInDataBase(phoneNumber, "phoneNumber")): + print("There is already an account with this phone number!") + elif(len(phoneNumber) == 10 and phoneNumber.isdigit()): #input must have 10 digits, which must all be numbers + break + print("Please input a valid phone number") + + + while(True): + SSN = input("Enter your Social Security Number: ") + + if(SSN == "cancel"): + return() + if(self.isInDataBase(SSN, "SSN")): + print("There is already an account with this SSN!") + elif(len(SSN) == 9 and SSN.isdigit()): #input must have 9 digits, which must all be numbers + break + print("Please input a valid SSN") + + + # add additional fields. For now, I am only doing First/Last name, email, password, phone number, and SSN + + #add confirm action conditional. + + while(True): + print("Create account with this information?") + print(">Name: " + firstName + " " + lastName + "\n>Email: " + email + "\n>Password: " + password + "\n>Phone number: " + phoneNumber + "\n>SSN: " + SSN) + isCorrect = input("1: Confirm, 2: Cancel ") + + if(isCorrect == "1"): + break + if(isCorrect == "2"): + return() + print("Please enter 1 or 2") + newUser = UserInfo(firstName, lastName, email, password, phoneNumber, SSN, {}, False) + self.UserArray.append(newUser) + + + def main(self): # do we want to bring the user to another loop once theyre logged in? + + while(self.loggedinUser is None): # Login Loop + print("1: login, 2: create account, 3: quit") + userIn = input("Select Option: ") + + if(userIn == "1"): # login + + if(self.login()): + user = self.loggedinUser #sets the user to the currently logged in user so we don't have to type self.loggedInUser... every time + print("welcome, " + user.firstName + user.lastName) + + while(self.loggedinUser is not None): + print("1: view account, 2: edit account info, 3: log out") + userIn = input("select Option:") + + if(userIn == "3"): #logs the user out + user = None + self.loggedinUser = None + print("You have logged out!") + break + break # placeholder code. Add account functionality later + + elif(userIn == "2"): # create account + self.create_account() + elif(userIn == "3"): # exit + break + + + + +if __name__=="__main__": + UserLogin().main() \ No newline at end of file diff --git a/Sprint 1/Usertest.py b/Sprint 1/Usertest.py index e69de29bb..5f515dc2a 100644 --- a/Sprint 1/Usertest.py +++ b/Sprint 1/Usertest.py @@ -0,0 +1,59 @@ +import unittest +from your_module import UserInfo, UserLogin # Replace 'your_module' with the actual module name + +class SimpleUserLoginTest(unittest.TestCase): + + def setUp(self): + """Set up a basic UserLogin instance and a sample user for testing.""" + self.user_login = UserLogin() + self.sample_user = UserInfo( + firstName="John", + lastName="Doe", + email="john.doe@example.com", + password="SecurePass123", + phoneNumber="1234567890", + SSN="123456789", + symptom_list=["fever", "cough"], + insurance=True + ) + self.user_login.UserArray.append(self.sample_user) + + def test_user_creation(self): + """Check if user info is set correctly when creating a UserInfo object.""" + user = UserInfo( + firstName="Jane", + lastName="Smith", + email="jane.smith@example.com", + password="password123", + phoneNumber="0987654321", + SSN="987654321", + symptom_list=["headache"], + insurance=False + ) + self.assertEqual(user.firstName, "Jane") + self.assertEqual(user.lastName, "Smith") + self.assertEqual(user.email, "jane.smith@example.com") + + def test_is_in_database_email(self): + """Test if an email is found in UserArray.""" + self.assertTrue(self.user_login.isInDataBase("john.doe@example.com", "email")) + self.assertFalse(self.user_login.isInDataBase("not_in_database@example.com", "email")) + + def test_is_in_database_phone(self): + """Test if a phone number is found in UserArray.""" + self.assertTrue(self.user_login.isInDataBase("1234567890", "phoneNumber")) + self.assertFalse(self.user_login.isInDataBase("0000000000", "phoneNumber")) + + def test_login_correct_credentials(self): + """Check login with correct email and password.""" + self.user_login.loggedinUser = None # Ensure no user is logged in + self.assertTrue(self.user_login.login("john.doe@example.com", "SecurePass123")) + self.assertIsNotNone(self.user_login.loggedinUser) # Logged-in user should be set + + def test_login_incorrect_credentials(self): + """Check login with incorrect password.""" + self.assertFalse(self.user_login.login("john.doe@example.com", "wrongpassword")) + self.assertIsNone(self.user_login.loggedinUser) # Should remain None for failed login + +if __name__ == '__main__': + unittest.main() From 064904ff9ce6e778a3634b9f8c97786bed7054e0 Mon Sep 17 00:00:00 2001 From: Jeremiah Robert Date: Fri, 1 Nov 2024 20:34:11 -0400 Subject: [PATCH 3/3] update with test file --- .vscode/settings.json | 11 +++++++++++ Sprint 1/__pycache__/UserLogon.cpython-311.pyc | Bin 0 -> 6729 bytes Sprint 1/__pycache__/test_unit.cpython-311.pyc | Bin 0 -> 4156 bytes Sprint 1/{Usertest.py => test_unit.py} | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 Sprint 1/__pycache__/UserLogon.cpython-311.pyc create mode 100644 Sprint 1/__pycache__/test_unit.cpython-311.pyc rename Sprint 1/{Usertest.py => test_unit.py} (96%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..788ef3982 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./Sprint 1", + "-p", + "*test*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/Sprint 1/__pycache__/UserLogon.cpython-311.pyc b/Sprint 1/__pycache__/UserLogon.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b2c35e942e0e35fd39bf148c90ae02f04b7e75b9 GIT binary patch literal 6729 zcmbsuTWs6b^^(+!BK4MENo>=#omfel#E*22)7W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SR422VxdJKcTBs7PKn8u-#D+lT3x}uIlpN6+??R?{ajH>AVy)1*_+j%ZXoh2{h9tWzmS>aJ5e3C3=*UZ3mD{$Qi zT(9*H8bc?{{*zY!$>M|EaR2tjU%y>?8_x7fGnFI9N;6hujI8G;&B!S$a>|IDszmxL zf#|<>{n2d(uVQ2o9xn64CO=~FBL=xEd!wP^<@zM@g&H=3neCg*ZaBm{2yR%4dDQ^? zszD4w7zh~PIYg=hwFhJ517NqS^BCX?nQ$SQT|I!C7)0RF3IGc2zdB7jhQVPr;B`5o zI}hs!e!4-}=ZKWVI)a~WAiPgG#_Om9KA;ac!gaJCG?c?C;bT?&;p6e8n5W9M|BWDN zDvp+_@8fhz-AJBDresOUHtfa|uVEB%&1+2l#`A9DP<~#$0K|A(r2PdzouMeIf<_Gc zy}xId^44h&1vc&nU*W#5G5Cr>H1}knL3!vlO@XnmhhLHYuRBM<76)HkDKmWr(^p~m h!kNcspPYTkM9TQcy~iTQ?2W^AI6igs0~K-Ge*kuw30wdG literal 0 HcmV?d00001 diff --git a/Sprint 1/__pycache__/test_unit.cpython-311.pyc b/Sprint 1/__pycache__/test_unit.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..32f900bd857e4af6b80f33b5b3ac405197f0d0f8 GIT binary patch literal 4156 zcmds4Pi))f75^xa_9t1MoiyhbaWzW2UA@Av-jPlJO|0@ugZ*}^z*|G<~_CG0V~CNPhPLKLnVhTD7Dy$H-BP`}D4WHqF456Eg*2?6DCiK~Lb z1BImk?N|DMQl&pjlGJ-6tCcGyHBi5(T6Vsz7PaF!;eK|X0eM91uD<;{xKE^@&u*U~ z$S9l=Qo;(a2uh#Quh2qBiF_N~p|E@S`xnRtXLg^g2YNc^y4|I*Eky{74diw}>S-Ve z=Q#iyjMd)Ds{Qfr%a--LD$2S7-Ik08Ay(m_#WlkeZ8!-{FQh#F zBcrH$;RQo|d14*dlwzpwslQ>vQ+cE84QADR)l@%|E$hO?cfBZ(nc2DdOP8m;NW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%a7=)n5gssU+*IgV?Rp$+zHlBCn?Zt*i5toJb4Jm-#1euo|3cX~@4;bRYL gjc~#VCz|}RjhhcX`TElbpKh>UD@^!N=wNI6H~D(rx&QzG literal 0 HcmV?d00001 diff --git a/Sprint 1/Usertest.py b/Sprint 1/test_unit.py similarity index 96% rename from Sprint 1/Usertest.py rename to Sprint 1/test_unit.py index 5f515dc2a..ff6d940f4 100644 --- a/Sprint 1/Usertest.py +++ b/Sprint 1/test_unit.py @@ -1,5 +1,5 @@ import unittest -from your_module import UserInfo, UserLogin # Replace 'your_module' with the actual module name +from UserLogon import UserInfo, UserLogin # Replace 'your_module' with the actual module name class SimpleUserLoginTest(unittest.TestCase):