Esempio n. 1
0
# userGroup.py
# Endpoints for managing returning corresponding user/group relationships
# Monica Mahon, 11/26/2019

from flask import Flask, request, render_template, redirect, url_for, session, jsonify
from flask_restful import Resource, request
import bcrypt
from SeniorProject import database
from bson.objectid import ObjectId

db = database.conn_DB()


class UserGroup(Resource):
    def get(self, f_id, g_id):
        res = {'msg': [], 'err': []}
        facilities = db.facilities
        users = db.users
        current_facility = facilities.find_one({'_id': ObjectId(f_id)})
        if current_facility:
            groups = current_facility.get('groups')
            group_id = next(g for g in groups
                            if g['_id'] == ObjectId(g_id))['_id']
            if group_id:
                users_in_group = list(
                    users.find({'groupID': ObjectId(g_id)}, {
                        'password': 0,
                        'answer': 0
                    }))
                return jsonify(users_in_group)
            else:
Esempio n. 2
0
from SeniorProject.resources.facility import Facility
from SeniorProject.resources.room import Room
from SeniorProject.resources.building import Building
from SeniorProject.resources.maintenance import Maintenance
from SeniorProject.new_json_encoder import New_JSON_Encoder
from SeniorProject.resources.group import Group
from SeniorProject.resources.userGroup import UserGroup
from SeniorProject.user_check import *
from SeniorProject.resources.userFacility import UserFacility
from SeniorProject.resources.userMaintenance import UserMaintenance

app = Flask(__name__)
api = Api(app)

app.json_encoder = New_JSON_Encoder
db = conn_DB()


@app.route('/')
@app.route('/home')
def home():
    return render_template('Home.html')


@app.route('/login', methods=['POST'])
def login():
    data = request.json
    users = db.users
    login_user = users.find_one({'email':
                                 data.get('email')})  # find user in db