コード例 #1
0
 def imageEncoding(file):
     image = face_recognition.load_image_file(file)
     try:
         face_encoding = face_recognition.face_encodings(image)[0]
     except IndexError:
         UserException.responseError(500, "Image was corrupted!")
     return face_encoding
コード例 #2
0
    def put(self, creditorId, debtorId):
        creditor = UserModel.findById(creditorId)
        debtor = UserModel.findById(debtorId)

        if not creditor or not debtor:
            UserException.responseError(404, 'User not found')

        result = UserModel.transfer(creditor, debtor)
        if not result:
            UserException.responseError(409,
                                        'Creditor do not have enough balance')
        return result
コード例 #3
0
 def post(self):
     file = request.files['file']
     if not file:
         UserException.responseError(400,
                                     'Bad Request - File was not informed')
     imageEncoding = FaceRecognition.imageEncoding(file)
     embeddings = UserModel.findAllEmbedding()
     id = FaceRecognition.compareImages(imageEncoding, embeddings)
     if id:
         user = UserModel.findById(id)
         return user.json()
     UserException.responseError(404, 'User not found')
コード例 #4
0
    def post(self):
        data = UserUtil.userParser.parse_args()
        user = UserModel(None, data['name'], data['email'], data['company'],
                         data['balance'], data['order'], data['embedding'])

        if UserModel.findByEmail(user.email):
            UserException.responseError(409, 'Email already exist')

        try:
            user.save()
        except:
            UserException.responseError(
                500, 'An error occurred during data update')
        return user.json(), 201
コード例 #5
0
 def post(self, id):
     user = UserModel.findById(id)
     if not user:
         UserException.responseError(404, 'User not found')
     file = request.files['file']
     if not file:
         UserException.responseError(400,
                                     'Bad Request - File was not informed')
     user.embedding = FaceRecognition.imageEncoding(file)
     embeddings = UserModel.findAllEmbedding()
     userId = FaceRecognition.compareImages(user.embedding, embeddings)
     if userId:
         UserException.responseError(409, 'User found - id: ' + str(userId))
     try:
         user.update(id)
     except:
         UserException.responseError(
             500, 'An error occurred during data update')
     return user.json(), 201
コード例 #6
0
    def put(self, id):
        if not UserModel.findById(id):
            UserException.responseError(404, 'User not found')

        data = UserUtil.userParser.parse_args()
        user = UserModel(id, data['name'], data['email'], data['company'],
                         data['balance'], data['order'], data['embedding'])

        result = UserModel.findByEmail(user.email)
        if result and result['Users_id'] != id:
            UserException.responseError(409, 'Email already exist')

        try:
            user.update(id)
        except:
            UserException.responseError(
                500, 'An error occurred during data update')
        return user.json()
コード例 #7
0
 def get(self, id):
     user = UserModel.findById(id)
     if not user:
         UserException.responseError(404, 'User not found')
     return user.json()
コード例 #8
0
 def get(self, userEmail):
     user = UserModel.findByEmail(userEmail)
     if not user:
         UserException.responseError(404, 'User not found')
     return user