Как я могу получить свой код, чтобы перейти после аутентификации пользователя - PullRequest
0 голосов
/ 03 марта 2020

Мой код написан на repl.it, и мне нужна помощь, чтобы остальная часть моего кода выполнялась, когда пользователь нажимает вниз, а затем код должен двигаться дальше, но это не так, и он просто зацикливается на аутентификации. (сайт: https://repl.it/@JamesGordon1 / Simple-chat-V01 )

Мой код:

from time import sleep as sp
from replit import clear
from sys import exit
clear()

from flask import Flask, render_template, request
app = Flask('app')
@app.route('/')
def hello_world():
    return render_template(
        'index.html',
        user_id=request.headers['X-Replit-User-Id'],
    )
app.run(host='0.0.0.0', port=8080)

players = ["Admin"]
def starter():
  clear()
  print ("Welcome to Simple chat!")
  print("")
  print ("What would you like to do?")
  print (" 1- Login")
  print (" 2- Sign up")
  start = input("(Only the number): ")
  if start == "1":
    clear()
    print("Sign-in to your account with your username")
    name = input("Username: ")
    found = 0
    with open("users.txt") as openfile:
        for line in openfile:
            for part in line.split():
                if name in part:
                    found = 1
    if found == 1:
      clear()
      players.append(name)
      print ("Welcome to the chatroom", part)
    else:
      clear()
      print ("User not found, please sign up if you dont have an acount")
      sp(1)
      starter()
  elif start == "2":
    def user():
      clear()
      print("Please type the username that you want")
      username = input("Username: ")
      taken = 0
      with open("users.txt") as openfile:
          for line in openfile:
              for part in line.split():
                  if username in part:
                      taken = 1
      if taken == 0:
        file = open("users.txt","a")
        file.write(username)
        file.write("\n")
        file.close()
        clear()
        print ("Thank you for signing-up with Simple chat", username)
        sp(1)
        starter()
      else:
        clear()
        print ("Username taken, please pick a difrent one")
        sp(1)
        user()
    user()
  else:
    starter()
  loop = "yes"
  while loop == "yes":
    message = str(input(name+": "))
    if message == "/leave":
      players.remove(name)
      loop = "no"
      exit(0)
    if message == "/kick":
      if user_id == 2421263:
        print ("Who do you want to kick?")
        kicked = input("I want to kick ")
        players.remove(kicked)
        # for the client
        # loop = "no"
    if message == "/clear":
      clear()
starter()

И в этом репле я пытаюсь сделать консоль чат, но мне также нужна помощь с сервером и клиентским кодом. Приведенный выше код является лишь грубым примером того, что я хочу сделать.

...