Esempio n. 1
0
def create_user(user):
    if user == 'admin':
        id = request.json['id']
        password = request.json['password']

        created = iam.create(id, password)
        if created:
            return {'id': id}
        else:
            return create_error(400,
                                'A user already exists with id %s' %
                                (id))
    else:
        return create_error(403, 'Only the admin user can create new users')
Esempio n. 2
0
def get_registration(registration_id):
    try:
        registration = Registration.get(Registration.id == registration_id)
        return registration._data
    except Registration.DoesNotExist:
        return create_error(status_code=404,
                            message=('A registration with the ID %s does not '
                                     'exist') % (registration_id))
Esempio n. 3
0
def login():
    id = request.json['id']
    password = request.json['password']

    if iam.authenticate(id, password):
        return {
            'token': tokenutils.generate_auth_token(token_secret, id, 3600)
        }
    else:
        return create_error(401, 'Invalid username or password')
Esempio n. 4
0
def delete_registration(registration_id, user):
    try:
        registration = Registration.get(Registration.id == registration_id,
                                        Registration.creator == user)
        id = registration.id
        registration.delete_instance()
        return {'id': id}
    except Registration.DoesNotExist:
        return create_error(status_code=404,
                            message=('A registration with the ID %s does not '
                                     ' exist') % (registration_id))
Esempio n. 5
0
def create_registration(user):
    registration_dict = request.json
    registration_dict['creator'] = user

    new_registration = Registration(**registration_dict)
    try:
        new_registration.save()
        return {'id': new_registration.id}
    except IntegrityError:
        return create_error(status_code=400,
                            message=('A registration for topic %s with '
                                     'container %s already exists') %
                            (registration_dict['topic'],
                             registration_dict['container']))