diff --git a/qbay/__init__.py b/qbay/__init__.py index d2a1cb4..103608f 100644 --- a/qbay/__init__.py +++ b/qbay/__init__.py @@ -5,3 +5,4 @@ app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../db.sqlite' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.app_context().push() diff --git a/qbay/__main__.py b/qbay/__main__.py index f08984c..493eda5 100644 --- a/qbay/__main__.py +++ b/qbay/__main__.py @@ -1,2 +1,25 @@ from qbay import * -from qbay.models import * \ No newline at end of file +from qbay.cli import login_page, regsiter_page + + +def main(): + while True: + selection = input( + 'Welcome. Please type 1 to login. ' + 'Or type 2 register. Or type 3 to exit') + selection = selection.strip() + if selection == '1': + user = login_page() + if user: + print(f'welcome {user.username}') + break + else: + print('login failed') + elif selection == '2': + regsiter_page() + elif selection == '3': + break + + +if __name__ == '__main__': + main() diff --git a/qbay/cli.py b/qbay/cli.py new file mode 100644 index 0000000..2633197 --- /dev/null +++ b/qbay/cli.py @@ -0,0 +1,19 @@ +from qbay.models import login, register + + +def login_page(): + email = input('Please input email') + password = input('Please input password:') + return login(email, password) + + +def regsiter_page(): + email = input('Please input email:') + password = input('Please input password:') + password_twice = input('Please input the password again:') + if password != password_twice: + print('password entered not the same') + elif register('default name', email, password): + print('registration succeeded') + else: + print('regisration failed.')