def chat(): form = RoomForm() if form.validate_on_submit(): db.session.add(g.user) #create a list of all existing rooms with this roomname room = Room.query.filter_by(roomname=form.roomname.data).first() # the room doesn't exist yet, so make it and set its name # and password to the given data if room == None: room = Room(roomname=form.roomname.data, password=form.roomkey.data, created_time=datetime.utcnow()) #delete room in 25 min remove_room.apply_async(args=[room.roomname], countdown=app.config['ROOM_TTL']) db.session.add(room) #the room does exist else: #if the 'attempted' password isn't the same as the room's password if room.password != form.roomkey.data: flash('That password\'s not right.', 'danger') return redirect(url_for('chat')) room.approve_user(g.user) db.session.commit() return redirect(url_for('room', roomname=form.roomname.data)) return render_template('chat.html', title='Chat', form=form)