Skip to content

Commit de87e5f

Browse files
committed
Create account implemented.
1 parent a803c09 commit de87e5f

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/snake_bnb/src/infrastructure/state.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
active_account = None
1+
from data.owners import Owner
2+
3+
active_account: Owner = None
24

35

46
def reload_account():

src/snake_bnb/src/program_hosts.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from colorama import Fore
22
from infrastructure.switchlang import switch
33
import infrastructure.state as state
4+
import servies.data_service as svc
45

56

67
def run():
@@ -14,8 +15,9 @@ def run():
1415

1516
with switch(action) as s:
1617
s.case('c', create_account)
17-
s.case('a', log_into_account)
18-
s.case('l', list_cages)
18+
s.case('a', create_account)
19+
s.case('l', log_into_account)
20+
s.case('y', list_cages)
1921
s.case('r', register_cage)
2022
s.case('u', update_availability)
2123
s.case('v', view_bookings)
@@ -34,8 +36,9 @@ def run():
3436

3537
def show_commands():
3638
print('What action would you like to take:')
37-
print('[C]reate an account')
39+
print('[C]reate an [a]ccount')
3840
print('[L]ogin to your account')
41+
print('List [y]our cages')
3942
print('[R]egister a cage')
4043
print('[U]pdate cage availability')
4144
print('[V]iew your bookings')
@@ -47,10 +50,17 @@ def show_commands():
4750

4851
def create_account():
4952
print(' ****************** REGISTER **************** ')
50-
# TODO: Get name & email
51-
# TODO: Create account, set as logged in.
5253

53-
print(" -------- NOT IMPLEMENTED -------- ")
54+
name = input('What is your name? ')
55+
email = input('What is your email? ')
56+
57+
old_account = svc.find_account_by_email(email)
58+
if old_account:
59+
error_msg(f"ERROR: Account with email {email} already exists.")
60+
return
61+
62+
state.active_account = svc.create_account(name, email)
63+
success_msg(f"Created new account with id {state.active_account.id}.")
5464

5565

5666
def log_into_account():
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from data.owners import Owner
2+
3+
4+
def create_account(name: str, email: str) -> Owner:
5+
owner = Owner()
6+
owner.name = name
7+
owner.email = email
8+
9+
owner.save()
10+
11+
return owner
12+
13+
14+
def find_account_by_email(email: str) -> Owner:
15+
owner = Owner.objects(email=email).first()
16+
return owner

0 commit comments

Comments
 (0)