예제 #1
0
파일: ChatRoutes.py 프로젝트: Sh4yy/Chatly
def username_available(username, user, session):

    users = User.find_username(username)
    groups = Group.find_username(username)

    available = not users and not groups
    return response({'username': username, 'available': available})
예제 #2
0
파일: ChatRoutes.py 프로젝트: Sh4yy/Chatly
def search_username(username, user, session):

    users = User.find_username(username)
    groups = Group.find_username(username)

    return response({
        'groups': [group.make_json(include_members=False) for group in groups],
        'users': [user.make_json() for user in users]
    })
예제 #3
0
파일: ChatRoutes.py 프로젝트: Sh4yy/Chatly
def create_group(user, session):

    json = request.json
    schema = Schema({'title': str, 'username': str})
    try:
        schema.validate(json)
    except SchemaError as err:
        return response(err.code)

    title = json['title']
    username = json['username']

    users = User.find_username(username)
    groups = Group.find_username(username)
    if users or groups:
        return error_response('username has been already taken')

    group = Group.new(user.id, title, username)
    return response({'group': group.make_json()})