fork download
  1. import json
  2.  
  3. class RegLog():
  4. """Класс регистрации/логина"""
  5. def __init__(self, **user):
  6. self.user = user
  7. #Проверка наличия файла пользователя
  8. def check_storge(self, user_file):
  9. user_file1 = user_file
  10. try:
  11. with open(user_file1) as f_obj:
  12. read_user_file = json.load(f_obj)
  13. except FileNotFoundError:
  14. return None
  15. else:
  16. return read_user_file
  17. #регистрация пользователя с созданием новго файла пользователя
  18. def register(self):
  19. nickname = input('Введи ник ')
  20. password = input('Введи пароль ')
  21. user_data = {'nickname': nickname, 'password': password}
  22. user_file = nickname + '.txt'
  23. with open(user_file, 'w') as f_obj:
  24. json.dump(user_data, f_obj)
  25.  
  26. #старт программы
  27. def LogIn(self):
  28. while True:
  29. work_begins_here = input('Введи login или reg ')
  30. if work_begins_here == 'login':
  31. nickname = input('Введи свой ник ')
  32. password = str(input('Введи свой пароль '))
  33. grub_user_data = [nickname, password]
  34. user_file = nickname + '.txt'
  35. check_storge = self.check_storge(user_file)
  36. if check_storge:
  37. user_file = nickname + '.txt'
  38. with open(user_file) as f_obj:
  39. read_user_file = json.load(f_obj)
  40. get_user_data_from_file = [read_user_file['nickname'], read_user_file['password']]
  41. if grub_user_data == get_user_data_from_file:
  42. print('Велкам '+ read_user_file['nickname'])
  43. else:
  44. print('Введен неверный логин или пароль')
  45. else:
  46. print('Такого пользователя не существует')
  47. if work_begins_here == 'reg':
  48. self.register()
  49.  
  50. user = RegLog(nickname='', password='')
  51. user.LogIn()
Runtime error #stdin #stdout #stderr 0.14s 23580KB
stdin
Standard input is empty
stdout
Введи login или reg 
stderr
Traceback (most recent call last):
  File "./prog.py", line 51, in <module>
  File "./prog.py", line 29, in LogIn
EOFError: EOF when reading a line