def register(): """register a model""" data = request.get_json() # authenticate the user name = data['name'] auth_token = request.headers.get('Authentication-Token') user = _token_loader(auth_token) if not user.is_authenticated: abort(401) # confirm no conflicts model = Model.query.filter_by(name=name).first() if model is not None: abort(409) model = Model(name) model.register(user) db.session.add(model) db.session.commit() return jsonify(status='success')
def validate_owner(model, request): """validates model ownership via auth token""" auth_token = request.headers.get('Authentication-Token') user = _token_loader(auth_token) if model.owner != user: abort(401)