def email_prompt(cls): # Email prompt while True: print("Enter B to go back.") email_input = input("Enter your e-mail:\n") if email_input.lower() == 'b': return MenuNode.current_node() if cls.email_is_valid(email_input): if cls.email_in_database(email_input): print( "\nUser associated with this e-mail address already exists!\n" ) print( "Try logging in instead or recovering your password.") decision = input(""" Enter M to return to Main Menu. Enter E to try with a different e-mail. """) if decision.lower() == "m": return MenuNode.default_node() elif decision.lower() == "e": continue else: return email_input else: print("\nPlease enter valid e-mail address!\n") continue
def not_enough_money(wallet): if wallet <= 0: print( "You have no money in your wallet. Please refill your wallet or sit and just watch the menu." ) time.sleep(3) return MenuNode.current_node()
def wallet_refill(): # player = User.logged # usr_dict = player.__dict__ req = RefRequest() req.save_request_in_reqs_box() time.sleep(3) return MenuNode.current_node()
def stop_watch_to_default_node(sec): while sec: minn, secc = divmod(sec, 60) timer = '{:02d}:{:02d}'.format(minn, secc) print(timer, end='\r') time.sleep(1) sec -= 1 return MenuNode.default_node()
def logout(): from structures.user_class import User, Admin if User.logged: if User.logged.is_admin: Admin.logged = None User.logged = None from guestMenu.main_Menu import MainMenu MenuNode.default_node = MainMenu MenuNode.current_node = MainMenu return MenuNode.default_node()
def register_script(cls): print("\nThank you for registering!\n") # time.sleep(1) valid_email = cls.email_prompt() valid_username = cls.username_prompt() os.system('clear') print(f''' \nWelcome {valid_username}!\n ''') valid_salt, valid_key = cls.password_prompt(valid_username) adm = getpass.getpass( "\nPress Enter to continue or type the admin access password to gain admin powers and " "permissions.\n") users = read_data_from_users_database() admins = read_data_from_admins_database() if adm == 'admin': # TODO hash and database export? new_admin = Admin(email=valid_email, username=valid_username, key=valid_key.hex(), salt=valid_salt.hex()) print("\nYou are an admin now.\n") new_admin_dictionary = new_admin.__dict__ admins['admins'].append(new_admin_dictionary) else: new_user = User(email=valid_email, username=valid_username, key=valid_key.hex(), salt=valid_salt.hex()) new_user_dictionary = new_user.__dict__ users['users'].append(new_user_dictionary) write_data_to_users_database(users) write_data_to_admins_database(admins) # TODO sending email to confirm the account print("You can now log in.") print(f"Returning the the main menu in:") cls.stop_watch_to_main_menu(3) print('\n') return MenuNode.default_node() # RegisterScript.register_script()
def system_wallet(): games = read_data_from_games_database() total_register = games['games_inf']['total_register'] for gamename in games['games']: print(f"\n{gamename}: {games['games'][gamename]['register']}\n") total_register += games['games'][gamename]['register'] write_data_to_games_database(games) from structures.user_class import User if User.logged.is_admin: print(f"Total number of points in the system:\n{total_register}\n") inp = input("Press Enter to continue.") return MenuNode.current_node()
def username_prompt(cls): # Username prompt while True: print("\nEnter B to go back.\n") username = input("\nEnter your username:\n") if username.lower() == 'b': return MenuNode.current_node() elif cls.username_is_valid(username): return username else: print("Please enter a new username.\n") continue
def display_personal_best(gamename): users = read_data_from_users_database() playing_user = User.logged for user in users['users']: if user['username'] == playing_user.username: try: game_best = user['my_best'][gamename] except KeyError: user['my_best'][gamename] = {} user['my_best'][gamename]['score'] = 0 game_best = user['my_best'][gamename] write_data_to_users_database(users) print(f"\nYour personal best in {gamename} is:\n" f"\t\t\t{game_best['score']} points.\n") inp = input("\nPress Enter to continue.\n") return MenuNode.current_node()
def display_top_n(gamename, n=5): os.system('clear') games = read_data_from_games_database() try: top5 = games['games'][gamename]['top5'] except KeyError: games['games'][gamename] = {} games['games'][gamename]['top5'] = [] top5 = games['games'][gamename]['top5'] if len(top5) == 0: print('\nThere are no records yet!\n') else: top5.sort(key=lambda x: x['score'], reverse=True) top5 = top5[:n] print('\n\n\n') for i, result in enumerate(top5): print( f"{i + 1}| {result['username']} | {result['score']} | {result['datetime_details']}\n" ) inp = input('\nPress Enter to continue.\n') return MenuNode.current_node()
def start_game(game): playing_user = game.setting_player() while True: players_choice, drawn_value, players_money_bet = game.game( playing_user) game.evaluating_results(players_choice, drawn_value, players_money_bet, playing_user) print(f"\nSession's score: {game.score}.") print( f"\nCurrent's session results: {game.current_session_results}." ) print(f"\nYour wallet's status: {playing_user.wallet}.") # Updating user's wallet in the database if User.logged: users = read_data_from_users_database() for user in users['users']: if user['username'] == playing_user.username: user['wallet'] += game.score write_data_to_users_database(users) # Updating game's register in the database. games = read_data_from_games_database() games['games'][game.name]['register'] += -game.score write_data_to_games_database(games) rnd = game.round_end(game.score, playing_user) if rnd: break else: continue print("Coming back to the previous menu...") time.sleep(5) return MenuNode.current_node()
from structures.menu_Node import MenuNode from Games.turtles_race.turtle_raceGame.turtle_race_FuncNode import TurtleRace_FuncNode from Games.turtles_race.turtle_raceBestScores.turtle_raceBestScores_FuncNode import turtle_raceBestScores content = {} options = [TurtleRace_FuncNode, turtle_raceBestScores] TurtleRace_Menu = MenuNode("Turtle Race", content, options=options)
from guestMenu.Login.loginFuncNode import login_FuncNode from guestMenu.Register.registerFuncNode import RegisterMenu from guestMenu.bestScores.best_scores import BestScores from mainMenuForUsers.chooseGame.chooseGameMenu import chooseGame_Menu from structures.menu_Node import MenuNode content = {} options = [chooseGame_Menu, login_FuncNode, RegisterMenu, BestScores] MainMenu = MenuNode("Main Menu", content, main_menu=True, options=options) MenuNode.current_node = MainMenu MenuNode.default_node = MainMenu
from structures.menu_Node import MenuNode from mainMenuForUsers.myAccount.myBest.myBest_script import my_bestTurtleRace, my_bestCoinFlip content = {} options = [my_bestTurtleRace, my_bestCoinFlip] myBest_MenuNode = MenuNode("My Best", content=content, options=options)
from structures.menu_Node import MenuNode from Games.coin_flip.coin_flipMenu import CoinFlip from Games.turtles_race.turtle_raceMenu import TurtleRace_Menu import structures.user_class as uc from importlib import reload choose_game = {} name = "Choose game" options = [CoinFlip, TurtleRace_Menu] chooseGame_Menu = MenuNode(name, choose_game, options=options) # if not MenuNode.check_logged_user(): # chooseGame_Menu.name = "PLay as guest"
from structures.menu_Node import MenuNode from mainMenuForUsers.myAccount.myWallet.walletStatus import walletStatus from mainMenuForUsers.myAccount.myWallet.walletRefillRequest import walletRefillRequest my_wallet = {} options = [walletStatus, walletRefillRequest] MyWallet = MenuNode("My Wallet", my_wallet, options=options)
def wallet_status(): user = User.logged print(f'\nYou have {user.wallet} points in your wallet.\n') inp = input("Enter any key to go back.") return MenuNode.current_node()
from structures.menu_Node import MenuNode from mainMenuForUsers.myAccount.myWallet.myWallet import MyWallet from mainMenuForUsers.myAccount.myBest.myBest_MenuNode import myBest_MenuNode my_account = {} options = [MyWallet, myBest_MenuNode] MyAccount = MenuNode("My Account", my_account, options=options)
def login_script(): # Searching for user in database identified_user = None while not identified_user: print('\n\nEnter R to return to main menu.') username_input = input('\nEnter your username or e-mail:\n') if username_input.lower() == 'r': return MenuNode.current_node() users = read_data_from_users_database() admins = read_data_from_admins_database() all_users = [] for adm in admins['admins']: all_users.append(adm) for usr in users['users']: all_users.append(usr) for user in all_users: if username_input == user['username'] or username_input == user[ 'email']: identified_user = User(dictionary=user) # if not dict_: ---> ---> identified_user.dictionary # dict_ = user # print(type(user)) # TODO Animation print("\nUser found!") break if not identified_user: print( "\nThis user does not exist. Try different username or register instead." ) time.sleep(2) continue # Verifying password count = 0 while count < 4: print('\n\nEnter R to return to main menu.') password_to_check = getpass.getpass("\nEnter your password:\n") if password_to_check.lower() == 'r': return MenuNode.current_node() salt = bytes.fromhex(identified_user.salt) new_key = hashlib.pbkdf2_hmac('sha256', password_to_check.encode('utf-8'), salt, 100000) if new_key.hex() == identified_user.key: print("\nPassword correct.\n") if identified_user.is_admin: Admin.logged = identified_user elif not identified_user.is_admin: User.logged = identified_user time.sleep(1) break else: print('\nPassword incorrect. Try again.\n') count += 1 if count > 3: print( "\nToo many tries. Please use 'Forget password' to regain access to your account.\n" ) print("\nResetting password...\n") # password_reset(identified_user) print(f'Returning to {MenuNode.default_node.name} in:') stop_watch_to_default_node(3) else: if identified_user.is_admin: User.logged = identified_user MenuNode.default_node = admin_Menu MenuNode.current_node = admin_Menu else: User.logged = identified_user MenuNode.default_node = MainMenuForUsers MenuNode.current_node = MainMenuForUsers return MenuNode.default_node()
from structures.menu_Node import MenuNode from Games.coin_flip.coin_flipGame.coin_flipGame_FuncNode import coin_flipFuncNode from Games.coin_flip.coin_flipBestScores.coin_flipBestScores_funcNode import coinFlipBestScores content = {} options = [coin_flipFuncNode, coinFlipBestScores] CoinFlip = MenuNode("Coin Flip", content, options=options)
from structures.menu_Node import MenuNode from Games.turtles_race.turtle_raceBestScores.turtle_raceBestScores_FuncNode import turtle_raceBestScores from Games.coin_flip.coin_flipBestScores.coin_flipBestScores_funcNode import coinFlipBestScores best_scores = {} options = [coinFlipBestScores, turtle_raceBestScores] BestScores = MenuNode("Best Scores", best_scores, options=options)
from structures.menu_Node import MenuNode from adminMenu.refill_requests.refill_Requests_FuncNode import refillRequests_FuncNode from mainMenuForUsers.Logout.logout_FuncNode import logOut_FuncNode from adminMenu.total_register.total_registerFuncNode import total_system_register from adminMenu.list_of_users.list_of_users_FuncNode import list_of_users_FuncNode content = {} options = [ refillRequests_FuncNode, list_of_users_FuncNode, total_system_register, logOut_FuncNode ] admin_Menu = MenuNode("Admin menu", content, main_menu=True, options=options) MenuNode.default_node = admin_Menu
from structures.menu_Node import MenuNode from mainMenuForUsers.myAccount.my_Account import MyAccount from mainMenuForUsers.Logout.logout_FuncNode import logOut_FuncNode # from MyBest import MyBest from mainMenuForUsers.chooseGame.chooseGameMenu import chooseGame_Menu content = {} options = [chooseGame_Menu, MyAccount, logOut_FuncNode] MainMenuForUsers = MenuNode("User's Main Menu", content, main_menu=True, options=options) MenuNode.default_node = MainMenuForUsers