예제 #1
0
def get():
    user = db_session.query(SystemUser).filter(
        SystemUser.token == request.headers.get('token')).one()
    if (user.system_user_id != None):
        # Token matches

        # Get the 20 most recent readings
        result = db_session.query(Reading).filter(
            Reading.system_user_id == user.system_user_id).order_by(
                Reading.time_taken.desc()).limit(20)

        resultJson = []
        db_session.close()

        for item in result:
            resultJson.append(item.__json__())

        return json.dumps(resultJson, indent=4, sort_keys=True,
                          default=str), 200, {
                              'content-type': 'application/json',
                              'Access-Control-Allow-Origin': '*'
                          }

    else:
        db_session.close()
        abort(403)
예제 #2
0
def auth():
    user = db_session.query(SystemUser).filter(
        or_(SystemUser.sis_id == str(request.form['username']).lower(),
            SystemUser.email == str(
                request.form['username']).lower())).first()
    if (user != None):
        # Check to see if password matches
        if (check_password_hash(user.password, request.form['password'])):

            if (user.token == None):
                # User does not have token, create one
                user.token = secrets.token_urlsafe(32)
                db_session.commit()

            resultJson = user.__json__()
            db_session.close()

            return json.dumps(resultJson,
                              indent=4,
                              sort_keys=True,
                              default=str), 200, {
                                  'content-type': 'application/json',
                                  'Access-Control-Allow-Origin': '*'
                              }
        else:
            db_session.close()
            abort(403)

    else:
        db_session.close()
        abort(403)
예제 #3
0
파일: app.py 프로젝트: tannercrook/wycorder
def testDB():
    user = db_session.query(SystemUser).filter(
        SystemUser.system_user_id == 1).one()
    if (user.system_user_id != None):
        return '<h1>DB Connected</h1>'
    else:
        return '<h2>Error connecting to database.</h2>'
예제 #4
0
def get():
    user = db_session.query(SystemUser).filter(
        SystemUser.token == request.headers.get('token')).first()
    if (user != None):
        # Token matches

        db_session.close()

        resultJson = user.__json__()

        return json.dumps(resultJson, indent=4, sort_keys=True,
                          default=str), 200, {
                              'content-type': 'application/json'
                          }

    else:
        db_session.close()
        abort(403)
예제 #5
0
def post():
    user = db_session.query(SystemUser).filter(
        SystemUser.token == request.headers.get('token')).one()
    if (user.system_user_id != None):
        # Token matches
        data = request.form
        reading = Reading()
        reading.system_user_id = user.system_user_id
        # Null for time_take (we will let the database handle it)
        #reading.time_taken = data['time_taken']
        reading.status = data['status']
        reading.fever_chills = data['fever_chills']
        reading.cough = data['cough']
        reading.sore_throat = data['sore_throat']
        reading.short_breath = data['short_breath']
        reading.fatigue = data['fatigue']
        reading.aches = data['aches']
        reading.taste_loss = data['taste_loss']
        reading.congestion = data['congestion']
        reading.nausea_vomit_diarrhea = data['nausea_vomit_diarrhea']
        reading.infectious_contact = data['infectious_contact']
        reading.temperature = data['temperature']

        db_session.add(reading)
        db_session.commit()
        db_session.close()

        return json.dumps({'status': data['status']},
                          indent=4,
                          sort_keys=True,
                          default=str), 200, {
                              'content-type': 'application/json',
                              'Access-Control-Allow-Origin': '*'
                          }

    else:
        db_session.close()
        abort(403)