routing updated to be more variable and on demand

- calendar json file now generated on demand at download request
- device fingerprint route now added
This commit is contained in:
2020-05-24 13:26:41 +02:00
parent 98a78f2102
commit c9cbb53eea
42 changed files with 51 additions and 729 deletions

View File

@ -145,6 +145,8 @@ def updateCalendars():
# a = flask.session['credentials']
# print(a, flush=True)
# print(current_user.getGoogleCredentials(), flush=True)
if current_user.getGoogleCredentials() == None:
return
credentials = google.oauth2.credentials.Credentials(**current_user.getGoogleCredentials())
calendars = caltojson.getCalendarList(credentials)

View File

@ -6,7 +6,7 @@ import sqlite3
# Third-party libraries
import flask
from flask import render_template, flash
from flask import Flask, redirect, request, url_for
from flask import Flask, redirect, request, url_for, jsonify
from flask_login import (
LoginManager,
current_user,
@ -18,6 +18,7 @@ import requests
import server.googleHandler as google
from backend.Routine import Routine
from server import login_manager, app, db
from server.forms import LoginForm, RegistrationForm, DeviceForm
from server.models import User, Calendar, Device
@ -116,6 +117,9 @@ def deleteAccount():
@app.route("/login/google")
def googlelogin():
if current_user.is_authenticated and current_user.getGoogleCredentials() != None:
return redirect(url_for('account'))
authorization_url = google.login()
return flask.redirect(authorization_url)
@ -123,6 +127,9 @@ def googlelogin():
@app.route("/login/google/callback")
def callback():
session, credentials = google.verifyResponse()
if current_user.is_authenticated and current_user.getGoogleCredentials == None:
current_user.setGoogleCredentials(credentials)
userinfo = session.get('https://www.googleapis.com/userinfo/v2/me').json()
# Create a user in your db with the information provided
@ -166,11 +173,25 @@ def credentials_to_dict(credentials):
'scopes': credentials.scopes}
@app.route("/userinfo/<path:user>/calendarevents.json")
def downloader(user):
path = "/home/calendarwatch/userinfo/" + user + "/"
print(path, flush=True)
return flask.send_from_directory(path, "calendarevents.json")
@app.route("/userinfo/<path:device>/calendarevents.json")
def downloader(device):
path = "/home/calendarwatch/userinfo/" + device + "/"
# return flask.send_from_directory(path, "calendarevents.json")
request_user = db.session.query(User).filter(User.id==device).first()
if request_user == None:
return jsonify(kind="unregistered")
routine = Routine()
routine.updateCalendar(request_user)
return jsonify(request_user.getJson())
@app.route("/devicefingerprint.json")
def generateDeviceFingerprint():
# Create Three Random Words
# check not in Device Database
# Save as new Device
# Send to User
return jsonify(deviceId="Carrot-Enamel-Storm")
# POST

Binary file not shown.

View File

@ -227,6 +227,10 @@ body *
color: #333;
}
.grey {
background-color: #ddd;
}
.sub.container .name {
margin-right: 1rem;
}

View File

@ -31,8 +31,12 @@
</div>
{% endfor %}
<div id=calendars class="container">
<a class="button" href="login/google">Google Calendar</a>
<a class="button" href="#" >Nextcloud Calendar</a>
</div>
<div class="container">
<div class="button addcalendar" style="width: auto; margin: 4rem">Add Calendar</div>
<a class="button addcalendar" href="/login/google" style="width: auto; margin: 4rem">Add Calendar</a>
</div>
<script type="text/javascript">

View File

@ -3,33 +3,33 @@
<div class="container">
<div style="font-weight: bold;width: 15rem; margin: 1rem">Device ID</div>
<div style="font-weight: bold;width: 10rem; margin: 1rem; padding-right: 5rem">Link Status</div>
<div style="font-weight: bold;width: 2rem; margin: 1rem">Action</div>
<div style="font-weight: bold;width: 10rem; margin: 1rem; padding-right: 4rem">Link Status</div>
<div style="font-weight: bold;width: 4rem; margin: 1rem">Action</div>
</div>
{% for item in devices %}
<div class="container">
<!--Name-->
<!--device id-->
<div style="width: 15rem; margin: 1rem;">{{ item.deviceId }}</div>
<!--Toggle-->
<div style="width: 10rem; margin: 1rem; padding-right: 5rem">
<!--link status-->
<div style="width: 10rem; margin: 1rem; padding-right: 4rem">
Connected
</div>
<!--Color Selector-->
<div style="width: 2rem; margin: 1rem;">
<!--action button-->
<div style="width: 4rem; margin: 1rem;">
<button type="button">Unlink</button>
</div>
</div>
{% endfor %}
<form action="" method="post">
<div class="container">
<div style="margin: 2rem">{{ form.hidden_tag() }}</div>
<div style="margin: 2rem">{{ form.deviceId.label }}</div>
<div style="margin: 2rem">{{ form.deviceId(size=32) }}</div>
<div style="margin: 2rem">{{ form.submit() }}</div>
<div class="container grey" style="margin-top: 3rem;">
<div>{{ form.hidden_tag() }}</div>
<div style="width: 7rem; margin: 1rem">{{ form.deviceId.label }}</div>
<div style="width: 12rem; margin: 1rem">{{ form.deviceId(size=24) }}</div>
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
</div>
</form>