mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Minor fix
This commit is contained in:
parent
9851513288
commit
2f770d1098
|
@ -74,3 +74,20 @@ def verify():
|
||||||
lib.utils.sendVerificationMail(user.display_name, user.email, code)
|
lib.utils.sendVerificationMail(user.display_name, user.email, code)
|
||||||
resp = {'error': 'Server could not find code, creating new one and sending email'}
|
resp = {'error': 'Server could not find code, creating new one and sending email'}
|
||||||
return Response(json.dumps(resp), status=500, mimetype='application/json')
|
return Response(json.dumps(resp), status=500, mimetype='application/json')
|
||||||
|
|
||||||
|
@authentication.route('/authentication/get-user-devices', methods=['GET'])
|
||||||
|
def uploadReadings():
|
||||||
|
uid = request.headers.get('UID')
|
||||||
|
if uid is None:
|
||||||
|
resp = {'error': 'UID not specified'}
|
||||||
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
|
||||||
|
# Save all the measurements
|
||||||
|
doc = firestore.client().collection(u'devices').document(uid).get()
|
||||||
|
if doc.exists:
|
||||||
|
list = doc.to_dict()['devices']
|
||||||
|
data = list
|
||||||
|
else:
|
||||||
|
data = []
|
||||||
|
res = {'devices': data}
|
||||||
|
return Response(json.dumps(res), status=200, mimetype='application/json')
|
||||||
|
|
16
api/data.py
16
api/data.py
|
@ -8,7 +8,7 @@ data = Blueprint('data', __name__)
|
||||||
|
|
||||||
@data.route('/readings/save', methods=['POST'])
|
@data.route('/readings/save', methods=['POST'])
|
||||||
def uploadReadings():
|
def uploadReadings():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
@ -36,7 +36,7 @@ def uploadReadings():
|
||||||
|
|
||||||
@data.route('/readings/getall', methods=['GET'])
|
@data.route('/readings/getall', methods=['GET'])
|
||||||
def getAllReadings():
|
def getAllReadings():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
@ -52,7 +52,7 @@ def getAllReadings():
|
||||||
|
|
||||||
@data.route('/readings/location/last', methods=['GET'])
|
@data.route('/readings/location/last', methods=['GET'])
|
||||||
def getLastLocation():
|
def getLastLocation():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
@ -72,7 +72,7 @@ def getLastLocation():
|
||||||
|
|
||||||
@data.route('/readings/steps/today', methods=['GET'])
|
@data.route('/readings/steps/today', methods=['GET'])
|
||||||
def getStepsToday():
|
def getStepsToday():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
@ -90,7 +90,7 @@ def getStepsToday():
|
||||||
|
|
||||||
@data.route('/readings/steps/last-five-days', methods=['GET'])
|
@data.route('/readings/steps/last-five-days', methods=['GET'])
|
||||||
def getStepsLastFiveDays():
|
def getStepsLastFiveDays():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
@ -121,13 +121,13 @@ def getStepsLastFiveDays():
|
||||||
|
|
||||||
@data.route('/readings/metrics-summary', methods=['GET'])
|
@data.route('/readings/metrics-summary', methods=['GET'])
|
||||||
def getMetricsSummary():
|
def getMetricsSummary():
|
||||||
deviceId = request.headers.get('deviceid')
|
deviceId = request.headers.get('Device-ID')
|
||||||
if deviceId is None:
|
if deviceId is None:
|
||||||
resp = {'error': 'Device not specified'}
|
resp = {'error': 'Device not specified'}
|
||||||
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
return Response(json.dumps(resp), status=400, mimetype='application/json')
|
||||||
|
|
||||||
upcomingMidnight = datetime.combine(datetime.today(), time.min) #+ timedelta(days=1)
|
upcomingMidnight = datetime.combine(datetime.today(), time.min) + timedelta(days=1)
|
||||||
lastMidnight = datetime.combine(datetime.today(), time.min) - timedelta(days=1)
|
lastMidnight = datetime.combine(datetime.today(), time.min)
|
||||||
doc = firestore.client().collection(u'readings').document(deviceId).get()
|
doc = firestore.client().collection(u'readings').document(deviceId).get()
|
||||||
|
|
||||||
if doc.exists:
|
if doc.exists:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from random import randint
|
from random import randint
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask_mail import Mail, Message
|
from flask_mail import Mail, Message
|
||||||
from firebase_admin import auth, firestore
|
from firebase_admin import firestore
|
||||||
|
|
||||||
def sendMail(subject, sender, recipients, body):
|
def sendMail(subject, sender, recipients, body):
|
||||||
mail = Mail(current_app)
|
mail = Mail(current_app)
|
||||||
|
@ -24,10 +24,3 @@ def sendVerificationMail(name, email, code):
|
||||||
body = '''Hey {}! Thank you for signing up for BarkFinder.
|
body = '''Hey {}! Thank you for signing up for BarkFinder.
|
||||||
In order to use our sevices, could you please verify your email address by logging in and entering this code {}'''.format(name, code)
|
In order to use our sevices, could you please verify your email address by logging in and entering this code {}'''.format(name, code)
|
||||||
sendMail(subject, sender, recipients, body)
|
sendMail(subject, sender, recipients, body)
|
||||||
|
|
||||||
def userLoggedInAndVerfied(token):
|
|
||||||
# Need frontend to test this
|
|
||||||
# decoded_token = auth.verify_id_token(token)
|
|
||||||
# uid = decoded_token['uid']
|
|
||||||
# isVerified = auth.get_user(uid).email_verified
|
|
||||||
return True #placeholder
|
|
1
main.py
1
main.py
|
@ -9,7 +9,6 @@ app = Flask(__name__)
|
||||||
app.register_blueprint(authentication)
|
app.register_blueprint(authentication)
|
||||||
app.register_blueprint(data)
|
app.register_blueprint(data)
|
||||||
|
|
||||||
|
|
||||||
# Initialize Mail instance
|
# Initialize Mail instance
|
||||||
app.config['MAIL_SERVER'] = MAIL_SERVER
|
app.config['MAIL_SERVER'] = MAIL_SERVER
|
||||||
app.config['MAIL_PORT'] = MAIL_PORT
|
app.config['MAIL_PORT'] = MAIL_PORT
|
||||||
|
|
Loading…
Reference in a new issue