Exemple #1
0
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})
Exemple #2
0
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]
    })
Exemple #3
0
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()})