diff --git a/app.py b/app.py index cb8eafb..fc6a3ef 100644 --- a/app.py +++ b/app.py @@ -90,6 +90,7 @@ class Calendar: self.color = color @app.route("/calendar") +@login_required def calendar(): ca1 = Calendar("Hightower", "#30ff30") ca2 = Calendar("Toast", "#66e230") @@ -97,10 +98,6 @@ def calendar(): return flask.render_template('calendar.html', calendars=calendars) - - - - @app.route('/test') def test_api_request(): if 'credentials' not in flask.session: @@ -117,7 +114,9 @@ def test_api_request(): # ACTION ITEM: In a production app, you likely want to save these # credentials in a persistent database instead. flask.session['credentials'] = credentials_to_dict(credentials) - + + with open('./userinfo/' + current_user.id + '/calendarevents.json', 'w') as outfile: + json.dump(todaysCal, outfile) return flask.jsonify(todaysCal) @app.route("/login/google") @@ -141,13 +140,11 @@ def login(): # Create flow instance to manage the OAuth 2.0 Authorization Grant Flow steps. flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file( CLIENT_SECRETS_FILE, scopes=SCOPES) - # The URI created here must exactly match one of the authorized redirect URIs # for the OAuth 2.0 client, which you configured in the API Console. If this # value doesn't match an authorized URI, you will get a 'redirect_uri_mismatch' # error. flow.redirect_uri = request.base_url + "/callback" - authorization_url, state = flow.authorization_url( # Enable offline access so that you can refresh an access token without # re-prompting the user for permission. Recommended for web server apps. @@ -183,7 +180,7 @@ def callback(): session = flow.authorized_session() userinfo = session.get('https://www.googleapis.com/userinfo/v2/me').json() - + # Create a user in your db with the information provided # by Google user = User( @@ -200,7 +197,7 @@ def callback(): # Begin user session by logging the user in login_user(user) return flask.redirect(flask.url_for('index')) - + @app.route("/logout") @login_required def logout(): @@ -216,14 +213,40 @@ def credentials_to_dict(credentials): 'scopes': credentials.scopes} -@app.route("/userinfo/107971745944668140075/calendarevents.json") -def downloader(): - path = "/home/raphael/dev/website_ws/website/login/userinfo/107971745944668140075" +@app.route("/userinfo//calendarevents.json") +def downloader(user): + print(user) + path = "/home/raphael/dev/website_ws/website/userinfo/" + user return flask.send_from_directory(path, "calendarevents.json") +# 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') + toggle = request.json.get('toggle') + + print(calId) + if color != None: + print(color) + if toggle != None: + print(toggle) + # toggle specific calendar of user + elif request.method == 'DELETE': + # do nothing + return 'NONE' + else: + # POST Error 405 + print("405") + + return 'OK' + if __name__ == "__main__": context = ('certificate/xip.io.crt', 'certificate/xip.io.key')#certificate and key files - app.run('192.168.68.103.xip.io', 1234, ssl_context=context, debug=True) + app.run('0.0.0.0', 1234, ssl_context=context, debug=True) diff --git a/database/sqlite_db b/database/sqlite_db index 01e423b..0f1b7df 100644 Binary files a/database/sqlite_db and b/database/sqlite_db differ diff --git a/template/calendar.html b/template/calendar.html index d0de596..288bdaf 100644 --- a/template/calendar.html +++ b/template/calendar.html @@ -1,35 +1,108 @@ {% extends "sidebar.html" %} {% block body%} + +
+
Calendar
+
Show on device
+
Color
+
+
-
Calendar
-
Show on device
-
Color
-
- -
{% for item in calendars %} -
{{ item.name }}
+
+ +
{{ item.name }}
-
- - -
+ +
+ + +
-
-
- - + +
+
+ +
+
- -
- {% endfor %} - +
+ + + {% endblock %} \ No newline at end of file diff --git a/template/sidebar.html b/template/sidebar.html index e2791ec..2d8fc66 100644 --- a/template/sidebar.html +++ b/template/sidebar.html @@ -6,10 +6,19 @@ + + + + + + + Index + +
View @@ -20,12 +29,15 @@
- + {% block body %} // content here {% endblock %}
+ + +