Example #1
0
    def post(self):
        form = DoorRegistrationForm()
        print 'Door registration request received'
        if not form.validate_on_submit():
            return form.errors,422

        if (g.user.role & 1) == 0:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        print 'Request door info from ' + 'http://' + form.address.data + ':5000' + '/request/doorinfo'
        try:
            response = requests.get('http://' + form.address.data + ':5000' + '/request/doorinfo', timeout=2)
        except:
            print "requested door unreachable"
            return 'requested door unreachable', 400

        print "create new door"
        response_data = json.loads(response.content)
        newDoor = Door(name = form.name.data, keyMask=response_data["keyMask"], address='http://' + form.address.data, local=0)
        logentry = Log(datetime.datetime.utcnow(), 'Test door', g.user.firstName + ' ' + g.user.lastName, g.user.email, 'Door ' + newDoor.name + ' on ' + newDoor.address + ' checked and registered', 'Door registered', 'L1', 1, 'Web based')
        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(newDoor)
            db.session.commit()
            print "Added door to database"
        except IntegrityError:
            print "Problems to add door to database"
            return make_response(jsonify({'error': 'eMail already registered'}), 400)

        print "return new door data for request"
        return DoorSerializer(newDoor).data
Example #2
0
    def post(self):
        form = DoorRegistrationForm()
        print 'Door registration request received'
        if not form.validate_on_submit():
            return form.errors, 422

        if g.user.role != 1:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        print 'Request door info from ' + 'http://' + form.address.data + ':5000' + '/request/doorinfo'

        pwd = base64.b64decode(form.password.data)
        auth_token = 'Basic ' + base64.b64encode(
            "[email protected]:" + pwd)
        headers = {'Authorization': auth_token}

        try:
            response = requests.get('http://' + form.address.data + ':5000' +
                                    '/request/doorinfo',
                                    timeout=6,
                                    headers=headers)
        except:
            print "requested door unreachable"
            return 'requested door unreachable', 400

        response_data = json.loads(response.content)
        newDoor = Door(name=response_data["name"],
                       displayName=form.name.data,
                       keyMask=response_data["keyMask"],
                       address='http://' + form.address.data,
                       local=0,
                       password=pwd)
        logentry = Action(
            datetime.datetime.utcnow(), config.NODE_NAME,
            g.user.firstName + ' ' + g.user.lastName, g.user.email,
            'Door ' + newDoor.name + ' on ' + newDoor.address +
            ' checked and registered', 'Door registered', 'L2', 1, 'Web based')
        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(newDoor)
            db.session.commit()
            print "Added door to database"
        except IntegrityError:
            print "Problems to add door to database"
            return make_response(
                jsonify({'error': 'eMail already registered'}), 400)

        print "return new door data for request"
        return DoorSerializer().dump(newDoor).data
Example #3
0
    def post(self):
        form = DoorRegistrationForm()
        print "Door registration request received"
        if not form.validate_on_submit():
            return form.errors, 422

        if (g.user.role & 1) == 0:
            return make_response(jsonify({"error": "Not authorized"}), 403)

        print "Request door info from " + "http://" + form.address.data + ":5000" + "/request/doorinfo"
        try:
            response = requests.get("http://" + form.address.data + ":5000" + "/request/doorinfo", timeout=2)
        except:
            print "requested door unreachable"
            return "requested door unreachable", 400

        print "create new door"
        response_data = json.loads(response.content)
        newDoor = Door(
            name=form.name.data, keyMask=response_data["keyMask"], address="http://" + form.address.data, local=0
        )
        logentry = Log(
            datetime.datetime.utcnow(),
            "Test door",
            g.user.firstName + " " + g.user.lastName,
            g.user.email,
            "Door " + newDoor.name + " on " + newDoor.address + " checked and registered",
            "Door registered",
            "L1",
            1,
            "Web based",
        )
        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(newDoor)
            db.session.commit()
            print "Added door to database"
        except IntegrityError:
            print "Problems to add door to database"
            return make_response(jsonify({"error": "eMail already registered"}), 400)

        print "return new door data for request"
        return DoorSerializer(newDoor).data
Example #4
0
    def post(self):
        form = DoorRegistrationForm()
        print 'Door registration request received'
        if not form.validate_on_submit():
            return form.errors, 422

        if g.user.role != 1:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        print 'Request door info from ' + 'http://' + form.address.data + ':5000' + '/request/doorinfo'

        pwd = base64.b64decode(form.password.data)
        auth_token = 'Basic ' + base64.b64encode("[email protected]:" + pwd)
        headers = {'Authorization' : auth_token}

        try:
            response = requests.get('http://' + form.address.data + ':5000' + '/request/doorinfo', timeout=6, headers = headers)
        except:
            print "requested door unreachable"
            return 'requested door unreachable', 400

        response_data = json.loads(response.content)
        newDoor = Door(name=response_data["name"], displayName= form.name.data, keyMask=response_data["keyMask"], address='http://' + form.address.data,
                       local=0, password = pwd)
        logentry = Action(datetime.datetime.utcnow(), config.NODE_NAME, g.user.firstName + ' ' + g.user.lastName,
                       g.user.email, 'Door ' + newDoor.name + ' on ' + newDoor.address + ' checked and registered',
                       'Door registered', 'L2', 1, 'Web based')
        try:
            db.session.add(logentry)
            db.session.commit()
            db.session.add(newDoor)
            db.session.commit()
            print "Added door to database"
        except IntegrityError:
            print "Problems to add door to database"
            return make_response(jsonify({'error': 'eMail already registered'}), 400)

        print "return new door data for request"
        return DoorSerializer().dump(newDoor).data