Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./Sprint 1",
"-p",
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
173 changes: 173 additions & 0 deletions Sprint 1/UserLogon.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added Sprint 1/__pycache__/UserLogon.cpython-311.pyc
Binary file not shown.
Binary file added Sprint 1/__pycache__/test_unit.cpython-311.pyc
Binary file not shown.
59 changes: 59 additions & 0 deletions Sprint 1/test_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import unittest
from UserLogon 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()