Exemplo n.º 1
0
    def register_user(email, password, name):
        user_data = Database.find_one('users', {"email": email})
        print("There is current user {}".format(user_data))

        if user_data is not None:
            raise err.UserIsAlreadyExist("The user with {} is already exist".format(email))
        
        if not Utils.email_is_valid(email):
            raise err.InvalidEmail("Please, write a valid email")
        
        userId = User(email, Utils.hash_password(password), name).save()
        userCursor = Database.find_one('users', {'_id': userId})

        return True, userCursor
Exemplo n.º 2
0
def add_attachment_to_card(cardId):
    image_file = request.files['attachment']

    contentType = image_file.content_type
    fileName = image_file.filename

    classCard, _ = Card.get_card_by_id(cardId)
    updatedCard, newImageId = classCard.add_attachment(image_file, contentType,
                                                       fileName)

    fsClass = FS.get(newImageId)
    imageStr = Utils.prepareImage(fsClass)

    imgAssigned = updatedCard['attachments']['assigned']

    if imgAssigned == newImageId:
        assignedImage = True
    else:
        assignedImage = False

    responseSchema = {
        '_id': updatedCard['_id'],
        'forList': updatedCard['forList'],
        'boardId': updatedCard['boardId'],
        'attachments': {
            'file_id': newImageId,
            'image': imageStr,
            'assigned': assignedImage,
            'filename': fsClass.filename,
            'uploadDate': fsClass.uploadDate
        }
    }

    return jsonify(responseSchema)
Exemplo n.º 3
0
def user_login():
    if request.method == "POST" and request.is_json:
        CONTENT = request.get_json()

        email = CONTENT['email']
        password = CONTENT['password']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                user = User.get_user_by_email(email)

                # if isinstance(user['photo'], ObjectId):

                #     fsClass = FS.get(user['photo'])
                #     photo = Utils.prepareImage(fsClass)
                #     user['photo'] = photo

                #     return jsonify(user)

                if user['photo']:
                    fsClass = FS.get(user['photo'])
                    photo = Utils.prepareImage(fsClass)
                    user['photo'] = photo

                return jsonify(user)

        except UserErrors.UserError as e:
            return jsonify(error=e.message)

    return "login form"
Exemplo n.º 4
0
    def get_attachment_in_string(cursors):
        cardWithImage = list()
        if len(cursors['attachments']['files']) is not 0:
            images = list()
            for ids in cursors['attachments']['files']:
                fsClass = FS.get(ids)

                filename = fsClass.filename
                uploadDate = fsClass.uploadDate

                imgStr = Utils.prepareImage(fsClass)

                imageDict = {
                    'file_id': ids,
                    'image': imgStr,
                    'filename': filename,
                    'uploadDate': uploadDate
                }
                images.append(imageDict)

            cardWithImage.append({
                **cursors, 'attachments': {
                    'files': images,
                    'assigned': cursors['attachments']['assigned']
                }
            })
        else:
            cardWithImage.append({**cursors})

        return cardWithImage
Exemplo n.º 5
0
    def is_login_valid(email, password):
        user_data = Database.find_one('users', {"email": email})

        if user_data is None:
            raise err.UserNotExist("User is not exist")
        if not Utils.check_hashed_password(password, user_data['password']):
            raise err.IncorectPassword("Wrond password")
        
        return True
Exemplo n.º 6
0
def upload_photo_for_team(teamId):
    image_file = request.files['photo']

    contentType = image_file.content_type
    fileName = image_file.filename

    teamClass, _ = Team.get_team_by_id(teamId)

    isUploaded = teamClass.upload_photo(image_file, contentType, fileName)
    fsCLass = FS.get(isUploaded)

    img_str = Utils.prepareImage(fsCLass)

    return jsonify(img_str)
Exemplo n.º 7
0
def update_user_photo():
    if request.method == 'POST':

        image_file = request.files['photo']

        contentType = image_file.content_type
        fileName = image_file.filename

        user = User.get_user_by_email(session['email'])
        classUser = User(**user)

        isUploaded = classUser.upload_photo(image_file, contentType, fileName)
        fsCLass = FS.get(isUploaded)

        img_str = Utils.prepareImage(fsCLass)

        return jsonify(img_str)
Exemplo n.º 8
0
    def return_with_assigned_files(cardsCursor):
        result = list()
        for card in cardsCursor:
            if card['attachments']['assigned']:
                fsClass = FS.get(card['attachments']['assigned'])
                imgStr = Utils.prepareImage(fsClass)
                prepareAttach = {
                    **card['attachments'], 'assigned': imgStr,
                    'file_id': card['attachments']['assigned']
                }
                result.append({**card, "attachments": prepareAttach})
            else:
                result.append({
                    **card, "attachments": {
                        **card['attachments'], 'assigned': None,
                        'file_id': card['attachments']['assigned']
                    }
                })

        return result
Exemplo n.º 9
0
def isHaveImage(team):
    if team['photo']:
        fsClass = FS.get(team['photo'])
        photo = Utils.prepareImage(fsClass)
        return {**team, 'photo': photo}
    return team