Exemplo n.º 1
0
def update_user(user=None):
    email = request.form.get("email")
    u = User.query.filter_by(id=user['id']).first()
    if email != u.email:
        # if updating email, ensure new email isn't already registered
        email_registered_by_user = User.query.filter_by(email=email).first()
        if email_registered_by_user:
            return jsonify({"error": "email registed already!"}), 409

    update_user_info(u)

    token = request.headers.get("token")
    account_data = Account(token, u.to_dict(return_email=True)).to_dict()
    refresh_user_data(token, u)
    return jsonify(account_data)
Exemplo n.º 2
0
def change_room(user=None):
    payload = request.get_json()
    mode = payload.get('mode')
    room = payload.get('room')

    u = User.query.filter_by(uuid=user['id']).first()
    if mode:
        u.mode = mode
    if room:
        u.room = room
    db.session.commit()

    token = request.headers.get("token")
    refresh_user_data(token, u)

    return 'ok'
Exemplo n.º 3
0
def create_room(user=None):

    u = User.query.filter_by(id=user['numId']).first()
    if u.credit < CREATE_ROOM_COST:
        return 'low credit', 402

    u.credit = u.credit - CREATE_ROOM_COST

    name = request.form.get("name")
    about = request.form.get("about")
    room = Room(name=name, about=about, owner=u.id)
    db.session.add(room)
    db.session.commit()

    token = request.headers.get("token")
    refresh_user_data(token, u)
    return "success"
Exemplo n.º 4
0
def create_room(user=None):

    u = User.query.filter_by(id=user['id']).first()

    if u.credit < CREATE_ROOM_COST:
        return 'low credit', 402

    u.credit = u.credit - CREATE_ROOM_COST

    room = Room(owner=u.id)

    db.session.add(room)
    db.session.commit()

    update_room_model(room)
    db.session.commit()

    token = request.headers.get("token")
    refresh_user_data(token, u)

    room_with_owner = RoomWithOwner(room.to_dict(), user)

    return jsonify(room_with_owner.to_dict())
Exemplo n.º 5
0
def update_user(user=None):
    name = request.form.get("name")
    about = request.form.get("about")
    avatar = request.files.get("avatar")

    u = User.query.filter_by(id=user['id']).first()

    if avatar:
        u.has_avatar = u.has_avatar + 1
        upload_file(avatar, f"{u.id}.jpg")

    u.name = name
    u.about = about

    # User.query.filter_by(id=user.id).update(
    #     {"name": user.name, "about": user.about, "has_avatar": user.has_avatar}
    # )

    db.session.commit()
    token = request.headers.get("token")
    account_data = Account(token, u.to_dict()).to_dict()
    refresh_user_data(token, u)
    return jsonify(account_data)