diff --git a/docker/calendarwatch/Dockerfile b/docker/calendarwatch/Dockerfile index 812799f..504bedd 100644 --- a/docker/calendarwatch/Dockerfile +++ b/docker/calendarwatch/Dockerfile @@ -2,9 +2,10 @@ FROM python:3.8-slim-buster RUN apt-get update && apt-get upgrade RUN pip3 install flask Flask-SQLAlchemy flask_migrate flask_login flask_wtf python-dotenv RUN apt-get install gcc libpcre3 libpcre3-dev libmariadbclient-dev -y -RUN pip3 install uwsgi email-validator RandomWords +RUN pip3 install uwsgi email-validator RandomWords icalevents RUN pip3 install google google-oauth google-auth-oauthlib google-api-python-client mysqlclient COPY docker-entrypoint.sh /usr/local/bin/ EXPOSE 8084 EXPOSE 3001 ENTRYPOINT ["docker-entrypoint.sh"] +# CMD tail -f /dev/null diff --git a/server/forms.py b/server/forms.py index 6f87ad4..6abe9d0 100644 --- a/server/forms.py +++ b/server/forms.py @@ -46,3 +46,12 @@ class DeviceForm(FlaskForm): device = Device.query.filter_by(deviceName=deviceName.data).first() if device is None: raise ValidationError('Device not Found') + + +class CalendarForm(FlaskForm): + iCalURL = StringField('New ical URL', validators=[DataRequired()]) + submit = SubmitField('Add URL') + + def validate_iCalURL (self, iCalURL): + return None + diff --git a/server/routes.py b/server/routes.py index dae831b..3c1817a 100644 --- a/server/routes.py +++ b/server/routes.py @@ -20,7 +20,7 @@ import requests import server.googleHandler as google from server import login_manager, app, db -from server.forms import LoginForm, RegistrationForm, DeviceForm +from server.forms import LoginForm, RegistrationForm, DeviceForm, CalendarForm import backend from database.models import User, Calendar, Device, GoogleToken @@ -94,11 +94,51 @@ def devices(): form=form) -@app.route("/calendar") +@app.route("/calendar", methods=['GET', 'POST', 'DELETE']) @login_required def calendar(): calendars = backend.calendarsFromDb(current_user) - return flask.render_template('calendar.html', calendars=calendars) + + form = CalendarForm() + if request.method == 'POST': + + if form.validate_on_submit(): + # try to add the submitted ical as a calendar + print(form.iCalURL.data, flush=True) + + # otherwise it is a javascript POST + else: + calId = request.json.get('calendar_id') + color = request.json.get('color', None) + toggle = request.json.get('toggle', None) + + if color != None: + current_user.updateCalendar(calId, color=color) + if toggle != None: + current_user.updateCalendar(calId, toggle=toggle) + # toggle specific calendar of user + calId = request.json.get('calendar_id') + color = request.json.get('color', None) + toggle = request.json.get('toggle', None) + + if color != None: + current_user.updateCalendar(calId, color=color) + if toggle != None: + current_user.updateCalendar(calId, toggle=toggle) + # toggle specific calendar of user + + return 'OK' + + elif request.method == 'DELETE': + # do nothing + return 'NONE' + else: + # POST Error 405 + print("405") + + return flask.render_template('calendar.html', calendars=calendars, form=form) + +# POST @app.route('/login/email', methods=['GET', 'POST']) def emaillogin(): @@ -243,27 +283,3 @@ def generateDeviceFingerprint(): # Send to Device return jsonify(deviceName=fingerprint) -# POST - -@app.route('/calendar', methods = ['POST', 'DELETE']) -@login_required -def user(): - if request.method == 'POST': - calId = request.json.get('calendar_id') - color = request.json.get('color', None) - toggle = request.json.get('toggle', None) - - if color != None: - current_user.updateCalendar(calId, color=color) - if toggle != None: - current_user.updateCalendar(calId, toggle=toggle) - # toggle specific calendar of user - - elif request.method == 'DELETE': - # do nothing - return 'NONE' - else: - # POST Error 405 - print("405") - - return 'OK' diff --git a/server/template/calendar.html b/server/template/calendar.html index b31b2e9..9b5ba1f 100644 --- a/server/template/calendar.html +++ b/server/template/calendar.html @@ -32,12 +32,21 @@ {% endfor %}
-