from flask import session, redirect, url_for, render_template, request
from . import main
from .forms import LoginForm
from flask_wtf import FlaskForm as BaseForm
listasalas=[]



@main.route('/', methods=['GET', 'POST'])
def index():
    """Login form to enter a room."""
    form = LoginForm()
    archivo = open("archivo.txt","a")
    a = "Usuario: " + str(form.name.data) + "  Sala: " + str(form.room.data) + " \n"
    archivo.write(str((a)))
    archivo.close()
    if form.validate_on_submit():
        if not (listasalas):
            listasalas.append(form.room.data)
        else:
            if(verificar(form.room.data)):
                print("ya esta")
            else:
                listasalas.append(form.room.data)
                    
            
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('index.html', form=form,lista=listasalas)

@main.route('/registrar', methods=['GET', 'POST'])
def registrar():
    form = LoginForm()
    if form.validate_on_submit():
        if not (listasalas):
            listasalas.append(form.room.data)
        else:
            if(verificar(form.room.data)):
                print("ya esta")
            else:
                listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('registrar.html', form=form,lista=listasalas)



@main.route('/ingresar', methods=['GET', 'POST'])
def verificar(dato):
    for a in listasalas:
        if(a==dato):
            return True
    return False

@main.route('/chat')
def chat():
    """Chat room. The user's name and room must be stored in
    the session."""
    name = session.get('name', '')
    room = session.get('room', '')
    if name == '' or room == '':
        return redirect(url_for('.index'))
    return render_template('chat.html', name=name, room=room)

c1ff3a3c0cb6b13d9e8d8ffa1a684dae557a19e4
<mask token>

<mask token>


@main.route('/', methods=['GET', 'POST'])
def index():
    """Login form to enter a room."""
    form = LoginForm()
    archivo = open('archivo.txt', 'a')
    a = 'Usuario: ' + str(form.name.data) + '  Sala: ' + str(form.room.data
        ) + ' \n'
    archivo.write(str(a))
    archivo.close()
    if form.validate_on_submit():
        if not listasalas:
            listasalas.append(form.room.data)
        elif verificar(form.room.data):
            print('ya esta')
        else:
            listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('index.html', form=form, lista=listasalas)


<mask token>


@main.route('/ingresar', methods=['GET', 'POST'])
def verificar(dato):
    for a in listasalas:
        if a == dato:
            return True
    return False


@main.route('/chat')
def chat():
    """Chat room. The user's name and room must be stored in
    the session."""
    name = session.get('name', '')
    room = session.get('room', '')
    if name == '' or room == '':
        return redirect(url_for('.index'))
    return render_template('chat.html', name=name, room=room)

<mask token>


@main.route('/', methods=['GET', 'POST'])
def index():
    """Login form to enter a room."""
    form = LoginForm()
    archivo = open('archivo.txt', 'a')
    a = 'Usuario: ' + str(form.name.data) + '  Sala: ' + str(form.room.data
        ) + ' \n'
    archivo.write(str(a))
    archivo.close()
    if form.validate_on_submit():
        if not listasalas:
            listasalas.append(form.room.data)
        elif verificar(form.room.data):
            print('ya esta')
        else:
            listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('index.html', form=form, lista=listasalas)


@main.route('/registrar', methods=['GET', 'POST'])
def registrar():
    form = LoginForm()
    if form.validate_on_submit():
        if not listasalas:
            listasalas.append(form.room.data)
        elif verificar(form.room.data):
            print('ya esta')
        else:
            listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('registrar.html', form=form, lista=listasalas)


@main.route('/ingresar', methods=['GET', 'POST'])
def verificar(dato):
    for a in listasalas:
        if a == dato:
            return True
    return False


@main.route('/chat')
def chat():
    """Chat room. The user's name and room must be stored in
    the session."""
    name = session.get('name', '')
    room = session.get('room', '')
    if name == '' or room == '':
        return redirect(url_for('.index'))
    return render_template('chat.html', name=name, room=room)

<mask token>
listasalas = []


@main.route('/', methods=['GET', 'POST'])
def index():
    """Login form to enter a room."""
    form = LoginForm()
    archivo = open('archivo.txt', 'a')
    a = 'Usuario: ' + str(form.name.data) + '  Sala: ' + str(form.room.data
        ) + ' \n'
    archivo.write(str(a))
    archivo.close()
    if form.validate_on_submit():
        if not listasalas:
            listasalas.append(form.room.data)
        elif verificar(form.room.data):
            print('ya esta')
        else:
            listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('index.html', form=form, lista=listasalas)


@main.route('/registrar', methods=['GET', 'POST'])
def registrar():
    form = LoginForm()
    if form.validate_on_submit():
        if not listasalas:
            listasalas.append(form.room.data)
        elif verificar(form.room.data):
            print('ya esta')
        else:
            listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('registrar.html', form=form, lista=listasalas)


@main.route('/ingresar', methods=['GET', 'POST'])
def verificar(dato):
    for a in listasalas:
        if a == dato:
            return True
    return False


@main.route('/chat')
def chat():
    """Chat room. The user's name and room must be stored in
    the session."""
    name = session.get('name', '')
    room = session.get('room', '')
    if name == '' or room == '':
        return redirect(url_for('.index'))
    return render_template('chat.html', name=name, room=room)

from flask import session, redirect, url_for, render_template, request
from . import main
from .forms import LoginForm
from flask_wtf import FlaskForm as BaseForm
listasalas=[]



@main.route('/', methods=['GET', 'POST'])
def index():
    """Login form to enter a room."""
    form = LoginForm()
    archivo = open("archivo.txt","a")
    a = "Usuario: " + str(form.name.data) + "  Sala: " + str(form.room.data) + " \n"
    archivo.write(str((a)))
    archivo.close()
    if form.validate_on_submit():
        if not (listasalas):
            listasalas.append(form.room.data)
        else:
            if(verificar(form.room.data)):
                print("ya esta")
            else:
                listasalas.append(form.room.data)
                    
            
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('index.html', form=form,lista=listasalas)

@main.route('/registrar', methods=['GET', 'POST'])
def registrar():
    form = LoginForm()
    if form.validate_on_submit():
        if not (listasalas):
            listasalas.append(form.room.data)
        else:
            if(verificar(form.room.data)):
                print("ya esta")
            else:
                listasalas.append(form.room.data)
        session['name'] = form.name.data
        session['room'] = form.room.data
        return redirect(url_for('.chat'))
    elif request.method == 'GET':
        form.name.data = session.get('name', '')
        form.room.data = session.get('room', '')
    return render_template('registrar.html', form=form,lista=listasalas)



@main.route('/ingresar', methods=['GET', 'POST'])
def verificar(dato):
    for a in listasalas:
        if(a==dato):
            return True
    return False

@main.route('/chat')
def chat():
    """Chat room. The user's name and room must be stored in
    the session."""
    name = session.get('name', '')
    room = session.get('room', '')
    if name == '' or room == '':
        return redirect(url_for('.index'))
    return render_template('chat.html', name=name, room=room)
