Esempio n. 1
0
def create_room():
    message = ''
    rooms = get_rooms_for_user(current_user.username)
    if request.method == "POST":
        room_name = request.form.get('room_name')
        usernames = [username.strip()
                     for username in request.form.get('members').split(',')]

        if len(room_name):
            for username in usernames:
                user = check_user(username)
                if username ==  "": 
                    
                    break
                elif user ==None :
                    print("bruhh")
                    message = f"user:\"{username}\" doesn't exist"
                    return render_template('index.html', message1=message, have_rooms=True, rooms=rooms)
                    break
            room_id = save_room(room_name, current_user.username)
            if current_user.username in usernames:
                usernames.remove(current_user.username)
            add_room_members(room_id, room_name, usernames,
                             current_user.username)
            return redirect(url_for('chat_room', room_id=room_id))
        else:
            message = 'Failed to Create room'

    return render_template('index.html', message1=message, have_rooms=True, rooms=rooms)
Esempio n. 2
0
def home():
    rooms = []
    if current_user.is_authenticated:
        rooms = get_rooms_for_user(current_user.username)
        return render_template("index.html", rooms=rooms)
    else:
        return render_template("home.html")
Esempio n. 3
0
def home():
    rooms = []
    if current_user.is_authenticated:
        rooms = get_rooms_for_user(current_user.username)
        print('rooms', rooms)
    else:
        return render_template('login.html')
    return render_template('index.html', rooms=rooms)
Esempio n. 4
0
def home():
    rooms = []
    try:
        if (current_user.is_authenticated()):
            rooms = get_rooms_for_user(current_user.username)
            return render_template("index.html", rooms=rooms)
    except:
        return render_template("home.html", rooms=rooms)
Esempio n. 5
0
def home():
    rooms = []
    have_rooms = False

    if current_user.is_authenticated:
        rooms = get_rooms_for_user(current_user.username)
        a = len(rooms)
        if a == 0:
            have_rooms = False
        else:
            have_rooms = True
    return render_template('index.html', rooms=rooms, have_rooms=have_rooms)
Esempio n. 6
0
def get_all_rooms():
    user_id = get_jwt_identity()
    user = get_user(user_id)
    room_list_raw = get_rooms_for_user(user_id)

    rooms_list = []

    for room_raw in room_list_raw:
        room_parsed = parse_json(room_raw)
        room_object = get_room(str(room_parsed['_id']['room_id']['$oid']))
        this_room = return_room(room_object, user.username, user_id)
        rooms_list.append(this_room)

    return jsonify(rooms_list)
Esempio n. 7
0
def get_rooms():
    user_id = get_jwt_identity()
    room_list_raw = get_rooms_for_user(user_id)
    room_list = []

    for item in room_list_raw:
        room_list.append(parse_json(item))

    id_list = []

    for item in room_list:
        id_list.append(item['_id']['room_id']['$oid'])

    return jsonify(id_list), 200
Esempio n. 8
0
def view_room(room_id):
    rooms = get_rooms_for_user(current_user.username)
    room = get_room(room_id)
    if room and is_room_member(room_id, current_user.username):
        room_members = get_room_members(room_id)
        messages = get_messages(room_id)
        return render_template('view_room.html',
                               username=current_user.username,
                               room=room,
                               room_members=room_members,
                               messages=messages,
                               rooms=rooms)
    else:
        return "Room not found", 404
Esempio n. 9
0
def view_room(room_id):
    room = get_room(room_id)
    try:
        is_dm = room['is_dm']
    except KeyError:
        is_dm = False
    if room and is_room_member(room_id, current_user.username):
        room_members = get_room_members(room_id)
        messages = get_messages(room_id)
        rooms = get_rooms_for_user(current_user.username)
        return render_template('view_room.html',
                               username=current_user.username,
                               this_room=room,
                               messages=messages,
                               room_members=room_members,
                               other_rooms=rooms,
                               is_dm=is_dm)
    else:
        return "Room not found", 404
Esempio n. 10
0
def chat_room(room_id):
    rooms = get_rooms_for_user(current_user.username)
    room = get_room(room_id)
    email = get_email(current_user.username)
    admins = []
    not_admin = []
    if room and is_room_member(room_id, current_user.username):
        room_members = get_room_members(room_id)
        for member in room_members:
            if is_room_admin(room_id, member['_id']['username']):
                admins.append(member['_id']['username'])
            else:
                not_admin.append(member['_id']['username'])

        messages = get_messages(room_id)
        return render_template('chat.html', admins=admins, rooms=rooms, username=current_user.username, not_admin=not_admin, email=email, room=room, room_members=room_members, room_id=room_id, messages=messages)
    else:

        return render_template('404.html', message='Room does not exist')
Esempio n. 11
0
def login():
    rooms = []
    if current_user.is_authenticated:
        rooms = db.get_rooms_for_user(current_user.username)
        res = [i for i in rooms]
        res = [i for i in res[0]]
        return render_template('index.html', rooms=res)

    message = ''
    if request.method == 'POST':
        username = request.form['username']
        password_input = request.form['password']
        user = db.get_user(username)

        if user and user.check_password(password_input):
            login_user(user)
            return redirect('/')
        else:
            message = 'Failed to login!'
    return render_template('login.html', message=message)
Esempio n. 12
0
def get_rooms(user_id):
    room_list_raw = get_rooms_for_user(user_id)
    room_list = []
    user = get_user(user_id)

    for item in room_list_raw:
        # parse the room
        room_parsed = parse_json(item)
        room_id = str(room_parsed['_id']['room_id']['$oid'])

        # get room members
        members_raw = get_room_members(room_id)
        members = list(
            map(lambda m: get_user(str(m['_id']['user_id'])).create_json(),
                members_raw))
        # ignoring check for is_room_member, some bug for me to complain about later

        # get room
        room_object = get_room(room_id)
        this_room = return_enumerated_room(room_object, user.username, user_id,
                                           members)
        room_list.append(this_room)

    return room_list  # returns an array of rooms
Esempio n. 13
0
def profile():
    rooms = []
    if current_user.is_authenticated:
        rooms = get_rooms_for_user(current_user.username)
    return render_template("profile.html", rooms=rooms)
Esempio n. 14
0
def home():
    rooms = []
    if current_user.is_authenticated:
        # db.py 에서 get_rooms_for_user 함수를 사용해서, 채팅방에 대한 정보를 가져온다.
        rooms = get_rooms_for_user(current_user.username)
    return render_template('index.html ', rooms=rooms)
Esempio n. 15
0
def home():
    if current_user.is_authenticated:
        rooms = get_rooms_for_user(current_user.username)
        return render_template('join_room.html', rooms=rooms)
    else:
        return redirect(url_for('login'))