def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = UserService.login(username, password) resp = make_response(redirect('/', '302')) resp.set_cookie('token', user['token']) return resp elif request.method == 'GET': return render_template('login.html')
# 输入操作 opt = input("\n\t输入操作编号:").strip() # 登陆系统,获取用户名和密码 if opt == "1": username = input("\n\t用户名:") password = getpass("\n\t密码:") # 退出系统 elif opt == "2": sys.exit() # 其他内容重新输入 else: print("\n\t输入有误,请重新输入!") time.sleep(1) continue # 调用登录函数,验证用户名和密码 result = __user_service.login(username, password) # 结果为假,验证失败,重新登陆 if result == False: print("\n\t用户名或密码错误,登录失败!(3秒后自动返回)") time.sleep(3) continue # 结果为真,获取身份角色 role = __user_service.search_user_role(username) print("\n\t登录成功!您的身份为:%s" % role) time.sleep(1) if role == "新闻编辑员": while True: break_flag = 0 cls() back_to_previous()