from authenticator import Authenticator from authorizor import Authorizor authenticator = Authenticator() authorizor = Authorizor(authenticator) authenticator.add_user("joe", "password") authorizor.add_permission("paint") authenticator.login("joe", "password") authorizor.permit_user("paint", "joe") print(authorizor.check_permission("paint", "joe"))
class AuthenticatorThread(QtCore.QThread): def __init__(self, main_window): QtCore.QThread.__init__(self) self.authenticator = Authenticator() self.main_window = main_window # Create a link between buttons and functions self.main_window.ui.add_user.clicked.connect(self.add_user) self.main_window.ui.remove_user.clicked.connect(self.remove_user) def add_user(self): image = self.main_window.get_cam_img() face_location = self.authenticator.face_crop(image) if face_location: top, right, bottom, left = face_location try: face = image[top:bottom, left:right] self.authenticator.add_user( face, self.main_window.ui.id_text.toPlainText()) except: self.main_window.ui.text_result.setText("Face not detected!") self.main_window.ui.img_result.setVisible(True) self.main_window.ui.img_result.setPixmap( QtGui.QPixmap("data/gui_images/alert.png")) return else: self.main_window.ui.text_result.setText("Face not detected!") self.main_window.ui.img_result.setVisible(True) self.main_window.ui.img_result.setPixmap( QtGui.QPixmap("data/gui_images/alert.png")) def remove_user(self): self.authenticator.remove_user( self.main_window.ui.id_text.toPlainText()) def run(self): life_proof_params = { 'img_reescale_width': 800, 'clipLimit': 3, 'tileGridSize': (8, 8), 'gray_reescale_width': 500, 'blur_ksize': (3, 3), 'blur_sigmaX': 0, 'thresh': 170, 'min_blob': 100, 'max_blob': 5000, 'min_radius': 4, 'max_radius': 30, 'y_line_dist': 8, 'total_var_limit': 20 } while True: cam_img = self.main_window.get_cam_img() face_location = self.authenticator.face_crop(cam_img) if face_location: top, right, bottom, left = face_location face = cam_img[top:bottom, left:right] classification_result = self.authenticator.face_classifier( face) if classification_result: life_proof_result = self.authenticator.life_proof( face, params=life_proof_params, debug=True) if life_proof_result: self.main_window.ui.text_result.setText( "%s\nPassed in life proof." % (classification_result)) self.main_window.ui.img_result.setVisible(True) self.main_window.ui.img_result.setPixmap( QtGui.QPixmap("data/gui_images/check.png")) else: self.main_window.ui.text_result.setText( "%s\nFailed in life proof." % (classification_result)) self.main_window.ui.img_result.setVisible(True) self.main_window.ui.img_result.setPixmap( QtGui.QPixmap("data/gui_images/alert.png")) else: self.main_window.ui.text_result.setText( "User does not exist in database.") self.main_window.ui.img_result.setVisible(True) self.main_window.ui.img_result.setPixmap( QtGui.QPixmap("data/gui_images/alert.png")) time.sleep(1) self.main_window.ui.img_result.setVisible(False) self.main_window.ui.text_result.setText("")