def add_user(user): """ 添加用户,仅管理员可见 :param user: 管理员身份信息 :return: none """ role_info = user_service.get_all_roles() username = input(Message.common_msg["username"]) check_null(username, Message.common_msg["username_error"], user, callback=add_user) if user_service.check_username(username): handle_error(Message.common_msg["username_duplicate"], add_user, user) pwd = get_password(Message.common_msg["password"]) email = get_email(Message.add_user["email"]) print(email) for i in role_info: print(Fore.BLUE + "\n%s. %s" % (i[0], i[1])) role_id = get_id(role_info, Message.common_msg["role_error"], Message.common_msg["role_id"]) handle_save(user_service.add_user, username, pwd, email, role_id) time_sleep(3) cls() print(Message.common_msg["success"]) manage_users(user)
def start(): """ 启动入口 :return: none """ print(Message.start_msg["welcome"]) input_val = input(Message.common_msg["prompt"]) if input_val == "1": cls() login() elif input_val == "2": exit_sys() else: handle_error(Message.common_msg["error"], start)
def manage_editor(user): """ 编辑身份管理页面 :param user: 编辑身份信息 :return: none """ print(Message.manage_msg["option_editor"]) print(Message.manage_msg["leave"]) input_val = input(Message.common_msg["prompt"]) if input_val == "1": cls() edit_news(user) elif input_val == "back": log_out() elif input_val == "exit": exit_sys() else: handle_error(Message.common_msg["error"], manage_editor, user)
def edit_user_input(user, users, index, page): """ 编辑用户输入界面,仅管理员可见 :param user: 管理员身份信息 :param users: 所有用户查询结果集 :param index: 用户输入编号 :param page: 当前页码 :return: none """ user_id = users[index - 1][0] user_info = user_service.get_user(user_id) role_info = user_service.get_all_roles() print(Message.edit_user["old_username"] % user_info[0][0]) new_username = input(Message.edit_user["new_username"]) check_null(new_username, Message.common_msg["username_error"], user, users, index, page, callback=edit_user_input) if new_username != user_info[0][0]: if user_service.check_username(new_username): handle_error(Message.common_msg["username_duplicate"], edit_user_input, user, users, index, page) new_pwd = get_password(Message.edit_user["new_pwd"]) print(Message.edit_user["old_email"] % user_info[0][1]) new_email = get_email(Message.edit_user["new_email"]) for i in role_info: print(Fore.BLUE + "\n%s. %s" % (i[0], i[1])) new_role_id = get_id(role_info, Message.common_msg["role_error"], Message.common_msg["role_id"]) handle_save(user_service.edit_user, new_username, new_pwd, new_email, new_role_id, user_id) time_sleep(3) cls() print(Message.common_msg["success"]) edit_user(user, page)
def manage_news(user): """ 管理新闻,仅管理员可见 :param user: 管理员身份信息 :return: none """ print(Message.manage_news_msg["option"]) print(Message.manage_msg["child_leave"]) input_val = input(Message.common_msg["prompt"]) if input_val == "1": cls() approval_news(user) elif input_val == "2": cls() delete_news(user) elif input_val == "back": cls() manage_admin(user) else: handle_error(Message.common_msg["error"], manage_news, user)
def login(): """ 登陆 :return: none """ username = input(Message.common_msg["username"]) check_null(username, Message.common_msg["username_error"], callback=login) password = getpass(Message.common_msg["password"]) if not password: password = input_cycle(password, Message.common_msg["pwd_error"], Message.common_msg["password"], kind="password") user = user_service.login(username, password) if not user: handle_error(Message.login_msg["login_error"], start) else: cls() if user["role"] == 1: manage_admin(user) elif user["role"] == 2: manage_editor(user)