def register(): inp_username = input('Enter username: '******' ') >= 1: raise ValueError('Username cannot contain spaces') if len(inp_username) == 0: raise ValueError('Username cannot be empty') if User.get_user_by_name(inp_username): raise ValueError('Username already taken') else: inp_password1 = getpass('Enter password: '******'Enter password second time: ') if inp_password1.count(' ') >= 1: raise ValueError('Password cannot contain spaces') if len(inp_password1) == 0: raise ValueError('Password cannot be empty') if inp_password1 == inp_password2: hashed_pas = hashing_input(inp_password1) User.create_user(inp_username, hashed_pas) else: raise ValueError("Password's don't match")
def user_posts(): inner_inp = input('Enter the user you want to find:\n') us = User.get_user_by_name(inner_inp) print( f"User {us.username} was registered at {us.date_of_registration}\n" f"his posts:") posts = Post.get_posts_by_user(us) for post in posts: print(f"{post.time} {post.user.username}:{post.data}")
def login(): inp_username = input('Enter username: '******'Enter password: '******'Login successful') return inp_username, True else: print('Login failed') return inp_username, False
def main_menu(): inp = input('Select what you want to do:\n' '1 - register\n' '2 - login\n' '3 - shutdown\n') try: if inp == '1': register() elif inp == '2': local_login, logged_in = login() if logged_in: us = User.get_user_by_name(local_login) user_menu = UserMenu(us.username, us.admin, us.super_admin) user_menu.main_menu() else: raise ValueError('Wrong username or password') elif inp == '3': return except ValueError as err: print('Error:', err) main_menu()
def add_post(self): inp = input('Enter what you want to write:\n') Post.add_post(User.get_user_by_name(self._username), inp)
def add_admin(): inp = input('Enter name of user you want to make an admin') us = User.get_user_by_name(inp) us.admin = True us.save()
def list_of_users(): users = User.get_all_users() for user in users: print( f"{user.username}, admin:{user.admin} super_admin:{user.super_admin}" )