Ejemplo n.º 1
0
def new_room():
    """Show the new room form. On submit, create and go to the new room."""

    # If no one is logged in, show the anon home page.
    if not g.user:
        return render_template("home-anon.html")

    form = NewRoomForm()

    # If conditional will return true when the form submits a response
    if form.validate_on_submit():
        try:
            if form.password.data:
                room = Room.create(form.id.data,
                                   form.password.data,
                                   is_private=True)
            else:
                room = Room.create(form.id.data)
            db.session.commit()
            return redirect(f"/room/{room.id}")

        except IntegrityError:
            flash("Room Name already taken", "danger")
            return render_template("/room/new-room.html", form=form)

        except:
            flash("Something went wrong. Try again!", "danger")
            return render_template("/room/new-room.html", form=form)

    return render_template("/room/new-room.html", form=form)
Ejemplo n.º 2
0
 def get(self, room_id):
     room = Room(room_id)
     if not room.exists():
         room.create()
     self.render("views/room.html",
                 video_url='',
                 room_id=room_id,
                 user_email=self.current_user.email,
                 user_token=self.current_user.token)
Ejemplo n.º 3
0
 def get(self, room_id):
     room = Room(room_id)
     if not room.exists():
         room.create()
     self.render("views/room.html",
                 video_url='',
                 room_id=room_id,
                 user_email=self.current_user.email,
                 user_token=self.current_user.token)
Ejemplo n.º 4
0
def add_new_room(user_id):  
    body = request.get_json()
    if body is None:
        raise APIException("You need to specify the request body as a json object", status_code=400)
    if 'name_room' not in body:
        raise APIException('You need to specify the name room', status_code=400)

    new_room = Room(name_room=body['name_room'], id_user= user_id)
    new_room.create()

    return jsonify({'status': 'OK', 'message': 'Room Added succesfully'}), 201
Ejemplo n.º 5
0
async def create(request: web.Request):
    user: User = await check_authorized(request)
    data = await request.json()
    roomname = data["name"]
    logo = data["logo"]
    if not roomname:
        return web.HTTPBadRequest()
    else:

        if Room.get_or_none(name=roomname, creator=user):
            return web.HTTPConflict()

        with db.atomic():
            default_options = LocationOptions.create()
            room = Room.create(
                name=roomname,
                creator=user,
                default_options=default_options,
            )

            if logo >= 0:
                room.logo_id = logo

            loc = Location.create(room=room, name="start", index=1)
            loc.create_floor()
            PlayerRoom.create(player=user, room=room, role=Role.DM, active_location=loc)
            room.save()
        return web.HTTPOk()
Ejemplo n.º 6
0
async def create(request):
    allow_new_sessions = config.getboolean("Access control",
                                           "allow_new_sessions")
    if not allow_new_sessions:
        return web.HTTPConflict(
            reason="This feature is disabled by administrator")

    user = await check_authorized(request)
    data = await request.json()
    roomname = data["name"]
    if not roomname:
        return web.HTTPBadRequest()
    else:
        with db.atomic():
            default_options = LocationOptions.create()
            room = Room.create(name=roomname,
                               creator=user,
                               default_options=default_options)
            loc = Location.create(room=room, name="start", index=1)
            loc.create_floor()
            PlayerRoom.create(player=user,
                              room=room,
                              role=Role.DM,
                              active_location=loc)
            room.save()
        return web.HTTPOk()
Ejemplo n.º 7
0
def rooms():
    if request.method == 'POST':
        room_data = Room(**get_request_data(request))
        if not room_data.validate():
            return json_response({"message": "Room form is invalid"}, 400)

        return room_data.create(db.rooms)
    else:
        return list_all(db.rooms, arguments=request.args)
Ejemplo n.º 8
0
    def setUp(self):
        """Make demo data."""

        User.query.delete()
        Room.query.delete()

        user = User.signup(**USER)
        room = Room.create(**ROOM)
        db.session.add_all([user, room])
        db.session.commit()

        self.user = user
        self.room_id = room.id
Ejemplo n.º 9
0
async def create(request):
    user = await check_authorized(request)
    data = await request.json()
    roomname = data["name"]
    if not roomname:
        return web.HTTPBadRequest()
    else:
        with db.atomic():
            room = Room.create(name=roomname, creator=user)
            loc = Location.create(room=room, name="start")
            loc.create_floor()
            room.dm_location = loc.name
            room.player_location = loc.name
            room.save()
        return web.HTTPOk()
Ejemplo n.º 10
0
async def create_room(request):
    user = await check_authorized(request)
    data = await request.post()
    roomname = data["room_name"]
    if not roomname:
        response = web.HTTPFound("/rooms")
    else:
        with db.atomic():
            room = Room.create(name=roomname, creator=user)
            loc = Location.create(room=room, name="start")
            loc.add_default_layers()
            room.dm_location = loc.name
            room.player_location = loc.name
            room.save()
        response = web.HTTPFound(f"/rooms/{user.name}/{roomname}")
    return response
Ejemplo n.º 11
0
def create_room():
    """
    Route creates new room and redirects to the lobby.
    It adds a new player to the room and sets session cookie if not present
    """
    username = request.forms.get("username")
    if len(username) == 0:
        return HTTPError(403, "Username too short")

    sessid = request.cookies.get("sessid", generate_sessid())
    room = Room.create(code=generate_room_code())
    player = Player.create(sessid=sessid, name=username, room=room)
    room.owner = player
    room.save()

    response.set_cookie("sessid", sessid, path="/")
    return redirect("/game/%s/lobby" % room.code)
Ejemplo n.º 12
0
 def post(self):
     data = json_decode(self.request.body)
     schema = {
         'type': {
             'type': 'integer',
             'required': True},
         'price': {
             'type': 'float',
             'required': True},
         'options': {
             'type': 'string'}
     }
     if not self.valid_data(schema, data):
         return
     room = Room.create(**data)
     self.set_response(
         content=dict(room=model_to_dict(room)),
         status=201,
         headers={'Location': self.reverse_url('room', room.id)})
Ejemplo n.º 13
0
async def create(request):
    user = await check_authorized(request)
    data = await request.json()
    roomname = data["name"]
    if not roomname:
        return web.HTTPBadRequest()
    else:
        with db.atomic():
            default_options = LocationOptions.create()
            room = Room.create(name=roomname,
                               creator=user,
                               default_options=default_options)
            loc = Location.create(room=room, name="start", index=1)
            loc.create_floor()
            PlayerRoom.create(player=user,
                              room=room,
                              role=Role.DM,
                              active_location=loc)
            room.save()
        return web.HTTPOk()
Ejemplo n.º 14
0
def book_room(user):

    choice = int(
        input(
            "Choose Type of Room:\n1. Single Room-5,000\n2. Deluxe-10,000\n3. Luxury-15,000\n4. Guest House-25,000"
        ))

    if choice == 1:
        dur = input("enter the duration of your stay")
        Room.create(owner=user, rname='single', cost=5000, duration=dur)
    elif choice == 2:
        dur = input("enter the duration of your stay")
        Room.create(owner=user, rname='deluxe', cost=10000, duration=dur)
    elif choice == 3:
        dur = input("enter the duration of your stay")
        Room.create(owner=user, rname='luxury', cost=15000, duration=dur)

    elif choice == 4:
        dur = input("enter the duration of your stay")
        Room.create(owner=user, rname='ghouse', cost=25000, duration=dur)
    else:
        print("invalid choice")
Ejemplo n.º 15
0
from models import db, User, Room
from app import app

# Create tables
db.drop_all()
db.create_all()

# Empty tables, just in case
User.query.delete()

# Default User values
user1 = User.signup(username="******", password="******")
user2 = User.signup(username="******", password="******")

# General Chat
room1 = Room.create(id="general")

for i in (user1, user2, room1):
    db.session.add(i)

db.session.commit()
Ejemplo n.º 16
0
def _create_rooms(size: int):
    for number in range(size):
        Room.create(number=number,
                    category=get_random(RoomType),
                    status=choice(ROOM_STATUSES)[0],
                    daily_amount=7500)