Example #1
0
    def post(self):
        print 'RFID assign request received'
        # check request paremeters (form)
        form = RFIDTagAssignForm()
        if not form.validate_on_submit():
            return form.errors, 422
        # check admin rights
        if g.user.role != 1:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        user = User.query.filter_by(email=form.email.data).first()

        if (user == None):
            return make_response(jsonify({'error': 'user not found'}), 400)

        if form.rfidTagId.data != None and form.rfidTagId.data != '':

            secretString = ''
            for i in range(0, 16):
                if i != 0:
                    secretString = secretString + '-'
                num = random.randrange(0, 256)
                secretString = secretString + format(num, '02X')

            user.cardID = form.rfidTagId.data
            user.cardSecret = secretString
            user.cardAuthBlock = 1
            user.cardAuthSector = 4
            user.cardAuthKeyA = config.RFID_GLOBAL_PASSWORD
            user.cardAuthKeyB = "FF-FF-FF-FF-FF-FF"

            print "User-secret: >" + str(user.cardSecret) + "<"
            print "User-keyA: >" + str(user.cardAuthKeyA) + "<"
            print "User-keyB: >" + str(user.cardAuthKeyB) + "<"

            if (backgroundWorker.assignRFIDTag(user) == False):
                print 'Error while assigning cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
                db.session.rollback()
                return make_response(jsonify({'error': 'user not found'}), 400)
            else:
                logentry = Action(
                    datetime.datetime.utcnow(), config.NODE_NAME,
                    g.user.firstName + ' ' + g.user.lastName, g.user.email,
                    'Assign RFID-tag ' + form.rfidTagId.data + ' to ' +
                    user.firstName + ' ' + user.lastName,
                    'Card administration', 'L2', 0, 'Card based')
                db.session.add(logentry)
                db.session.commit()
        print 'Assigned cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
        return '', 201
Example #2
0
    def post(self):
        print 'RFID assign request received'
        # check request paremeters (form)
        form = RFIDTagAssignForm()
        if not form.validate_on_submit():
            return form.errors, 422
        #check admin rights
        if (g.user.role & 1) == 0:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        user = User.query.filter_by(email=form.email.data).first()

        if(user == None):
            return make_response(jsonify({'error': 'user not found'}), 400)


        if form.rfidTagId.data != None and form.rfidTagId.data != '':
            authKeyA = ""
            authKeyB = ""
            secret = ""

            user.cardID = form.rfidTagId.data
            user.cardAuthBlock = 1
            user.cardAuthSector = 4


            for i in range(0, 6):
                authKeyA = authKeyA + format(255, '02X') + ' '
                authKeyB = authKeyB + format(random.randrange(0, 256), '02X') + ' '

            for i in range(0, 16):
                secret = secret + format(random.randrange(0, 256), '02X') + ' '

            print 'authKeyA:' + authKeyA
            print 'authKeyB:' + authKeyB
            print 'secret:' + secret

            user.cardAuthKeyA = authKeyA
            user.cardAuthKeyB = authKeyB
            user.cardSecret = secret

            if(backgroundWorker.assignRFIDTag(user) == False):
                print 'Error while assigning cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
                db.session.rollback()
                return make_response(jsonify({'error': 'user not found'}), 400)
            else:
                db.session.commit()

        print 'Assigned cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
        return '', 201
Example #3
0
    def post(self):
        print "RFID assign request received"
        # check request paremeters (form)
        form = RFIDTagAssignForm()
        if not form.validate_on_submit():
            return form.errors, 422
        # check admin rights
        if (g.user.role & 1) == 0:
            return make_response(jsonify({"error": "Not authorized"}), 403)

        user = User.query.filter_by(email=form.email.data).first()

        if user == None:
            return make_response(jsonify({"error": "user not found"}), 400)

        if form.rfidTagId.data != None and form.rfidTagId.data != "":
            authKeyA = ""
            authKeyB = ""
            secret = ""

            user.cardID = form.rfidTagId.data
            user.cardAuthBlock = 1
            user.cardAuthSector = 4

            for i in range(0, 6):
                authKeyA = authKeyA + format(255, "02X") + " "
                authKeyB = authKeyB + format(random.randrange(0, 256), "02X") + " "

            for i in range(0, 16):
                secret = secret + format(random.randrange(0, 256), "02X") + " "

            print "authKeyA:" + authKeyA
            print "authKeyB:" + authKeyB
            print "secret:" + secret

            user.cardAuthKeyA = authKeyA
            user.cardAuthKeyB = authKeyB
            user.cardSecret = secret

            if backgroundWorker.assignRFIDTag(user) == False:
                print "Error while assigning cardID " + form.rfidTagId.data + " to " + user.firstName + " " + user.lastName
                db.session.rollback()
                return make_response(jsonify({"error": "user not found"}), 400)
            else:
                db.session.commit()

        print "Assigned cardID " + form.rfidTagId.data + " to " + user.firstName + " " + user.lastName
        return "", 201
Example #4
0
    def post(self):
        print 'RFID assign request received'
        # check request paremeters (form)
        form = RFIDTagAssignForm()
        if not form.validate_on_submit():
            return form.errors, 422
        # check admin rights
        if g.user.role != 1:
            return make_response(jsonify({'error': 'Not authorized'}), 403)

        user = User.query.filter_by(email=form.email.data).first()

        if (user == None):
            return make_response(jsonify({'error': 'user not found'}), 400)

        if form.rfidTagId.data != None and form.rfidTagId.data != '':

            secretString = ''
            for i in range(0,16):
                if i != 0:
                    secretString = secretString + '-'
                num = random.randrange(0, 256)
                secretString = secretString + format(num, '02X')

            user.cardID = form.rfidTagId.data
            user.cardSecret = secretString
            user.cardAuthBlock = 1
            user.cardAuthSector = 4
            user.cardAuthKeyA = config.RFID_GLOBAL_PASSWORD
            user.cardAuthKeyB = "FF-FF-FF-FF-FF-FF"

            print "User-secret: >" + user.cardSecret + "<"
            print "User-keyA: >" + user.cardAuthKeyA + "<"
            print "User-keyB: >" + user.cardAuthKeyB + "<"

            if (backgroundWorker.assignRFIDTag(user) == False):
                print 'Error while assigning cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
                db.session.rollback()
                return make_response(jsonify({'error': 'user not found'}), 400)
            else:
                logentry = Action(datetime.datetime.utcnow(), config.NODE_NAME, g.user.firstName + ' ' + g.user.lastName,
                               g.user.email, 'Assign RFID-tag ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName, 'Card administration',
                               'L2', 0, 'Card based')
                db.session.add(logentry)
                db.session.commit()
        print 'Assigned cardID ' + form.rfidTagId.data + ' to ' + user.firstName + ' ' + user.lastName
        return '', 201