Index: src/mapservice/server_impl/controllers/DevicesController.py
===================================================================
--- src/mapservice/server_impl/controllers/DevicesController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
+++ src/mapservice/server_impl/controllers/DevicesController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
@@ -0,0 +1,75 @@
+'''
+    Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+import connexion
+
+from ..database.Model import User, Device, db
+from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
+
+def devices_get(name=None, order_by=None, offset=None, limit=None):
+	query = None
+	
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+
+	query = Device.query.filter_by(owner = user)
+	if name is not None:
+		query = query.filter(Device.name.like('%{}%'.format(name)))
+
+	result = []
+	for device in query.offset(offset).limit(limit):
+		result.append(device.to_dict())
+	return result
+
+def devices_get_by_id(id):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	device = Device.query.filter_by(owner = user).filter_by(id=id).all()
+	if len(device) != 1:
+		raise MapserviceNotFound
+	return device[0].to_dict()
+
+def devices_create(device_creation):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	comment = ""
+	if device_creation.comment:
+		comment = device_creation.comment
+	
+	device = Device(name=device_creation.name, owner=user, sensor_depth=device_creation.sensor_depth, comment=comment)
+	db.session.add(device)
+	db.session.commit()
+	return device.to_dict()
+
+def devices_device_delete(id):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	if not Device.query.filter_by(owner = user).filter_by(id=id).delete():
+		raise MapserviceBadRequest(detail="Could not delete device with id {}".format(id))
+	db.session.commit()
+	
+	query = Device.query.filter_by(owner = user)
+	result = []
+	for device in query:
+		result.append(device.to_dict())
+	return result
Index: src/mapservice/server_impl/controllers/LogsController.py
===================================================================
--- src/mapservice/server_impl/controllers/LogsController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
+++ src/mapservice/server_impl/controllers/LogsController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
@@ -0,0 +1,135 @@
+'''
+    Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+import connexion
+
+from ..database.Model import User, Log, LogEntry, Water, Device, Gauge, ProcessingStatus, Queue, db
+from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
+from ..tasks.tasks import log_process
+
+def logs_get(submitter=None, order_by=None, offset=None, limit=None):
+	query = None
+	
+	if submitter is not None:
+		submitter = User.query.filter_by(username=submitter).all()
+		if len(submitter) != 1:
+			raise MapserviceNotFound(detail="Could not find the submitter with id {}".format(submitter))
+		submitter = submitter[0]
+
+	query = None
+	if submitter is not None:
+		query = Log.query.filter_by(submitter = submitter)
+		
+	if query is None:
+		query = Log.query
+	
+	result = []
+	for log in query.offset(offset).limit(limit):
+		result.append(log.meta_data())
+	return result
+
+def logs_log_get_by_id(id):
+	log = Log.query.filter_by(id=id).all()
+	if len(log) != 1:
+		raise MapserviceNotFound
+	if connexion.request.headers['Accept'] == "application/geo+json":
+		return log[0].to_geojson(), 200, {'Content-Type': 'application/geo+json; charset=utf-8'}
+	return log[0].log()
+
+def logs_log_create(log_creation):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+
+	water = Water.query.filter_by(id=log_creation.water).all()
+	if len(water) != 1:
+		raise MapserviceBadRequest(detail='Water {} not found database'.format(log_creation.water))
+	water = water[0]
+	
+	device = Device.query.filter_by(id=log_creation.device).all()
+	if len(device) != 1:
+		raise MapserviceBadRequest(detail='Device {} not found in database'.format(log_creation.device))
+	device = device[0]
+	
+	gauge = Gauge.query.filter_by(id=log_creation.gauge).all()
+	if len(gauge) != 1:
+		raise MapserviceBadRequest(detail='Gauge {} not found in database'.format(log_creation.gauge))
+	gauge = gauge[0]
+	
+	if log_creation.gauge_height is None:
+		raise MapserviceBadRequest(detail='Gauge Height (Stage) missing')
+	else:
+		try:
+			float(log_creation.gauge_height)
+		except ValueError:
+			raise MapserviceBadRequest(detail='Gauge Height (Stage) {} is no number'.format(log_creation.gauge_height))
+
+	if log_creation.comment is None:
+		log_creation.comment = ""
+	
+	log = Log(submitter=user, water=water, device=device, gauge=gauge, gauge_height=log_creation.gauge_height, start=None, end=None, comment=log_creation.comment)
+	db.session.add(log)
+	db.session.commit()
+	return log.meta_data()
+
+def logs_log_upload(log_id, body=None):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	if body is None or not body:
+		raise MapserviceBadRequest(detail='No log data')
+	
+	processing_state = ProcessingStatus.query.filter_by(label='Queued for Parsing').all()
+	if len(processing_state) != 1:
+		raise MapserviceBadRequest(detail='Processing status Queued for Parsing not found database')
+	processing_state = processing_state[0]
+	
+	log = Log.query.filter_by(id=log_id).all()
+	if len(log) != 1:
+		raise MapserviceBadRequest(detail='Log {} not found database'.format(log_id))
+	log = log[0]
+	
+	# check if Log has already log entries
+	if LogEntry.query.filter_by(log=log).count() > 0:
+		raise MapserviceBadRequest(detail='Log {} has already log entries. Aborting'.format(log_id))
+
+	# Add Log to Queued table and change the processing state of Log
+	queue = Queue(log=log)
+	db.session.add(queue)
+	log.processingstatus = processing_state
+	db.session.commit()
+	
+	# request log parsing
+	log_process.delay(log.id, body.decode())
+	
+	return log.meta_data()
+
+def logs_log_delete(id):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	if not Log.query.filter_by(submitter = user).filter_by(id=id).delete():
+		raise MapserviceBadRequest(detail="Could not delete log with id {}".format(id))
+	db.session.commit()
+	
+	query = Log.query.filter_by(submitter = user)
+	result = []
+	for log in query:
+		result.append(log.meta_data())
+	return result
+
Index: src/mapservice/server_impl/controllers/TilesController.py
===================================================================
--- src/mapservice/server_impl/controllers/TilesController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
+++ src/mapservice/server_impl/controllers/TilesController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
@@ -0,0 +1,58 @@
+'''
+    Copyright (C) 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+
+import connexion
+import flask
+import os
+
+from ..HttpErrors import MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound
+
+def tiles_tile_get(accuracy, resolution, zoom, x_tile, y_tile):
+	if not 'TILES_CACHE_PATH' in flask.current_app.config or not os.access(flask.current_app.config['TILES_CACHE_PATH'], os.R_OK):
+		raise MapserviceInternalServerError(detail='TILES_CACHE_PATH not configured or not accessible')
+	tiles_cache_path = flask.current_app.config['TILES_CACHE_PATH']
+	
+	if not 'TILES_DENSITIES' in flask.current_app.config:
+		raise MapserviceInternalServerError(details='TILES_DENSITIES not configured')
+	tiles_densities = flask.current_app.config['TILES_DENSITIES']
+	
+	if not 'TILES_DENSITY_BASEE' in flask.current_app.config:
+		raise MapserviceInternalServerError(details='TILES_DENSITY_BASEE not configured')
+	tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
+	
+	if not 'TILES_SKIP_EMPTY' in flask.current_app.config:
+		raise MapserviceInternalServerError(details='TILES_SKIP_EMPTY not configured')
+	tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
+	
+	if accuracy == 'high':
+		accuracy = '{}_{}'.format(max(tiles_densities), tiles_densitiy_base)
+	elif accuracy == 'low':
+		accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
+	else:
+		raise MapserviceBadRequest(details='No valid accuracy requested. Valid are high, low. Requested was: {}'.format(accuracy))
+	
+	tile__empty_path = os.path.join(tiles_cache_path, '{}/{}/empty_tile.png'.format(accuracy, resolution))
+	tile_path = os.path.join(tiles_cache_path, '{}/{}/{}/{}/{}.png'.format(accuracy, resolution, zoom, x_tile, y_tile))
+	if not os.path.isfile(tile_path):
+		if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
+			raise MapserviceNotFound(detail='Tile ({}, {}) for accuracy {} with resolution {} at zoomlevel {} not found'.format(x_tile, y_tile, accuracy, resolution, zoom))
+		tile_path = tile__empty_path
+	
+	response = flask.send_file(tile_path, mimetype='image/png', as_attachment=True, attachment_filename='{}.png'.format(y_tile))
+	response.direct_passthrough = False
+	#response.headers['Content-Transfer-Encoding']='base64'
+	return response
Index: src/mapservice/server_impl/controllers/UsersController.py
===================================================================
--- src/mapservice/server_impl/controllers/UsersController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
+++ src/mapservice/server_impl/controllers/UsersController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
@@ -0,0 +1,128 @@
+'''
+    Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+import connexion
+
+import datetime
+import hashlib
+import re
+import flask
+from flask import request, render_template
+from flask_mail import Message
+
+from .. import mail
+from ..database.Model import User, ApiKey, db
+from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
+
+mail_regex = re.compile('[^@]+@[^@]+\.[^@]+')
+
+def users_activate(activationCode):
+	user = User.query.filter_by(activation_code=activationCode).all()
+	
+	webclient = flask.current_app.config['MAPSERVICE_WEBCLIENT']
+	
+	if len(user) != 1:
+		return 'Bad Request', 302, {'Location': 'activation_failed.html'}
+	
+	user = user[0]
+	user.activated = True
+	user.activation_code = ""
+	db.session.commit()
+	return 'Success', 302, {'Location': '{}/login'.format(webclient)}
+
+def users_api_key_create():
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	api_key = hashlib.md5("{}{}".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S"), user.salt).encode()).hexdigest()
+	user.apikeys.append(ApiKey(user=user, key=api_key))
+	db.session.commit()
+
+	result = []
+	for apiKey in user.apikeys:
+		result.append(apiKey.key)
+	return result
+
+def users_api_key_delete(api_key):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	if not ApiKey.query.filter_by(key=api_key).delete():
+		raise MapserviceBadRequest(detail="Could not delete api key {}".format(api_key))
+	db.session.commit()
+	
+	result = []
+	for apiKey in user.apikeys:
+		result.append(apiKey.key)
+	return result
+
+def users_get():
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	return user_to_dict(user)
+
+def users_register(user_creation):
+	if user_creation is None:
+		raise MapserviceBadRequest(detail='No data specified')
+	if user_creation.username is None or not user_creation.username:
+		raise MapserviceBadRequest(detail='No username given')
+	if user_creation.password is None or not user_creation.password:
+		raise MapserviceBadRequest(detail='No password given')
+	if user_creation.first_name is None or not user_creation.first_name:
+		raise MapserviceBadRequest(detail='No first name given')
+	if user_creation.last_name is None or not user_creation.last_name:
+		raise MapserviceBadRequest(detail='No last name given')
+	if user_creation.email is None or not user_creation.email:
+		raise MapserviceBadRequest(detail='No email given')
+	if not mail_regex.match(user_creation.email):
+		raise MapserviceBadRequest(detail='Email contains more than one @, no @ or no .')
+	if user_creation.license_accepted is None or not user_creation.license_accepted:
+		raise MapserviceBadRequest(detail='You must accept the license to register an account')
+	
+	# add user to the database
+	user = User.factory(user_creation.username, user_creation.password, user_creation.email)
+	user.first_name = user_creation.first_name
+	user.last_name = user_creation.last_name
+	user.license_accepted = user_creation.license_accepted
+	db.session.add(user)
+	db.session.commit()
+	
+	# send activation mail
+	activation_url = '{}/activate/{}'.format(request.base_url, user.activation_code)
+	
+	message = Message("Activate your GNUBoat account", recipients=[user.email])
+	message.body = 'Hello {},\nthank you for support the project with your own measurings. To activate your GNUBoat account, visit {}.\nKind regards,\nYour GNUBoat team'.format(user.first_name, activation_url)
+	message.html = render_template('activation_mail.html', first_name=user.first_name, activation_url=activation_url)
+	mail.send(message)
+	
+	return user_to_dict(user)
+
+def user_to_dict(user):
+	# create user dict and remove not needed entries
+	result = user.to_dict()
+	del result['password']
+	del result['salt']
+	del result['activationCode']
+	
+	# add api keys of the user to the result dict
+	result['apiKeys'] = []
+	for apiKey in user.apikeys:
+		result['apiKeys'].append(apiKey.key)
+	return result
Index: src/mapservice/server_impl/controllers/WatersController.py
===================================================================
--- src/mapservice/server_impl/controllers/WatersController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
+++ src/mapservice/server_impl/controllers/WatersController.py	(revision ae2ff15d6963a93c67e87e175ea31292b8bb3d28)
@@ -0,0 +1,150 @@
+'''
+    Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+'''
+import connexion
+
+from ..database.Model import User, Water, Gauge, Log, db
+from ..HttpErrors import MapserviceBadRequest, MapserviceUnauthorized, MapserviceNotFound
+
+def waters_get(name=None, manager=None, stakeholder=None, order_by=None, offset=None, limit=None):
+	query = None
+	
+	if manager is not None:
+		manager = User.query.filter_by(username=manager).all()
+		if len(manager) != 1:
+			raise MapserviceNotFound(detail="Could not find the manager with id {}".format(manager))
+		manager = manager[0]
+
+	query = Water.query
+	if manager is not None:
+		query = query.filter_by(manager = manager)
+	if name is not None:
+		query = query.filter(Water.name.like('%{}%'.format(name)))
+	
+	waters = []
+	for water in query.offset(offset).limit(limit):
+		waters.append(water)
+		
+	# handle stakeholder
+	if stakeholder is not None:
+		stakeholder = User.query.filter_by(username=stakeholder).all()
+		if len(stakeholder) != 1:
+			raise MapserviceNotFound(details='Stakeholder not found')
+		stakeholder = stakeholder[0]
+		
+		# add waters, where the stakeholder has added logs to
+		query_log = Log.query.filter_by(submitter=stakeholder).all()
+		for log in query_log:
+			already_found = False
+			for water in waters:
+				if water.id == log.water.id:
+					already_found = True
+					break
+			if not already_found:
+				waters.append(log.water)
+		
+		# add waters, where the stakeholder has added gauges to
+		query_gauge = Gauge.query.filter_by(manager=stakeholder).all()
+		for gauge in query_gauge:
+			already_found = False
+			for water in waters:
+				if water.id == gauge.water.id:
+					already_found = True
+					break
+			if not already_found:
+				waters.append(gauge.water)
+				
+	result = []
+	for water in waters:
+		result.append(water.to_dict())
+	
+	return result
+
+def waters_get_by_id(id):
+	water = Water.query.filter_by(id=id).all()
+	if len(water) != 1:
+		raise MapserviceNotFound
+	return water[0].to_dict()
+
+def waters_create(water_creation):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	water = Water(name=water_creation.name, manager=user, osm_id=water_creation.osm_id, osm_type=water_creation.osm_type)
+	db.session.add(water)
+	db.session.commit()
+	return water.to_dict()
+
+def waters_gauge_get_by_id(water_id, gauge_id):
+	water = Water.query.filter_by(id=water_id).all()
+	if len(water) != 1:
+		raise MapserviceBadRequest(detail="Water with id {} not found".format(water_id))
+	water = water[0]
+
+	gauge = Gauge.query.filter_by(water=water).filter_by(id=gauge_id).all()
+	if len(gauge) != 1:
+		raise MapserviceNotFound(detail="Did not find gauge with id {} for water {}".format(gauge_id, water.name))
+	if connexion.request.headers['Accept'] == "application/geo+json":
+		return gauge[0].to_geojson(), 200, {'Content-Type': 'application/geo+json; charset=utf-8'}
+	return gauge[0].to_dict()
+
+
+def waters_gauge_create(water_id, gauge_creation):
+	user = User.loggedin_user()
+	if user is None:
+		raise MapserviceUnauthorized
+	
+	water = Water.query.filter_by(id=water_id).all()
+	if len(water) != 1:
+		raise MapserviceBadRequest(detail="Did not find water with id {}".format(water_id))
+	water = water[0]
+	
+	location = 'SRID=4326;POINT({:.6} {:.6})'.format(gauge_creation.location[0], gauge_creation.location[1])
+	gauge = Gauge(name=gauge_creation.name, manager=user, water=water, location=location, reference_water_level_gauge_height=gauge_creation.reference_water_level_gauge_height, comment=gauge_creation.comment)
+	db.session.add(gauge)
+	db.session.commit()
+	return gauge.to_dict()
+
+def waters_gauges_get(water_id, name, manager, order_by, offset, limit):
+	water = Water.query.filter_by(id=water_id).all()
+	if len(water) != 1:
+		raise MapserviceBadRequest(detail="Did not find water with id {}".format(water_id))
+	
+	query = None
+	
+	if manager is not None:
+		manager = User.query.filter_by(username=manager).all()
+		if len(manager) != 1:
+			raise MapserviceNotFound(detail="Could not find the manager with id {}".format(manager))
+		manager = manager[0]
+
+	query = Gauge.query.filter_by(id=water_id)
+	if manager is not None:
+		if manager and name is not None:
+			query = query.filter_by(manager = manager).filter(Gauge.name.like('%{}%'.format(name)))
+		elif manager:
+			query = query.filter_by(manager = manager)
+	elif name is not None:
+		query = query.filter(Gauge.name.like('%{}%'.format(name)))
+	
+	result = []
+	for gauge in query.offset(offset).limit(limit):
+		if connexion.request.headers['Accept'] == "application/geo+json":
+			result.append(gauge.to_geojson())
+		else:
+			result.append(gauge.to_dict())
+	return result
