Exemple #1
0
def createFolder():
    action = DB()
    users = action.getUserList()
    # session['folder'] = action.getFoldersByUserId(session['id'])
    return render_template('core/createfolder.html',
                           users=users,
                           active='createFolder')
Exemple #2
0
 def saveImage(self, image, folder_id, user_id, edited):
     baseRoot = app.config['BASE_UPLOAD_FOLDER']
     location = baseRoot + str(user_id)
     # return os.walk(os.path.join(baseRoot, folder))[1]
     try:
         filename = image.filename.strip()
         possible_duplicate = 0
         i = 1
         originalFilename = filename
         while os.path.isfile(location + '/' + filename):
             possible_duplicate = 1
             filename = str(i) + '_' + originalFilename
             i += 1
         image.save(os.path.join(location, filename))
         action = DB()
         imageObject = Image.open(image)
         width, height = imageObject.size
         resolution = '[' + str(height) + ' x ' + str(width) + ']'
         action.addImage(filename, folder_id, user_id, 'storage/' + str(user_id), resolution, possible_duplicate)
         if not action.checkHasFeatureImageByFolderId(folder_id):
             action.setFeatureImageByFolderId(user_id, filename, folder_id)
         if edited == '1':
             action.setEditedTagByImageId(filename, folder_id)
         maxsize = app.config['WEBVIEW_SIZE']
         imageObject.thumbnail(maxsize)
         thumbnailFilename = 'mid_' + filename
         imageObject.save(os.path.join(location, thumbnailFilename))
         maxsize = app.config['THUMBNAIL_SIZE']
         imageObject.thumbnail(maxsize)
         thumbnailFilename = 'thumb_' + filename
         imageObject.save(os.path.join(location, thumbnailFilename))
         # return jsonify(url=session['url'])
     except Exception as e:
          flash('Image was not saved: ' + e, 'danger')
Exemple #3
0
def generateRegisterAction():
    if request.method == 'POST':
        string = request.form['inputString']
        action = DB()
        hash = action.createToken(string)
        flash('photos.timnummyphotography.com/register/' + hash, 'success')
    return render_template('core/generate.html')
Exemple #4
0
def userList():
    action = DB()
    users = action.getUserList()
    return render_template('core/user-list.html',
                           users=users,
                           active='userList',
                           showpassword=request.args.get('password'))
Exemple #5
0
def registerAction():
    if request.method == 'POST':
        action = DB()
        first = request.form['inputFirstName']
        last = request.form['inputLastName']
        email = request.form['inputEmail']
        password = request.form['inputPassword']
        confirmPassword = request.form['confirmPassword']
        hash = request.form['inputHash']
        if not action.checkHash(hash):
            flash('Register link is no longer valid', 'danger')
            return render_template('core/register.html')
        if action.checkUserExists(email):
            flash('Email already used. Did you mean to log in?', 'danger')
            return render_template('core/register.html')
        if password != confirmPassword:
            flash('Passwords don\'t match', 'danger')
            return render_template('core/register.html')
        if len(password) < 6:
            flash('Password too short', 'danger')
            return render_template('core/register.html')
        registrant = User(first, last, email, password)
        user_id = action.createUser(registrant)
        File().makeDirectory(user_id)
        action.voidHash(hash)
        signinAction(email, password)
    return redirect('/')
Exemple #6
0
def generatePasswordResetAction():
    if request.method == 'POST':
        email = request.form['inputEmail']
        action = DB()
        hash = action.createPasswordResetToken(email)
        flash('photos.timnummyphotography.com/reset-password/' + hash,
              'success')
    return render_template('core/generateresetpassword.html')
Exemple #7
0
def unshare():
    if request.method == 'POST':
        action = DB()
        action.unshareImageByImageId(request.form['inputImage'], session['id'])
        flash('Image removed from public album.', 'success')
        if request.form['inputZoom'] == str(1):
            return redirect('/album/' + request.form['inputAlbum'] + '/' +
                            request.form['inputImage'])
        return redirect('/album/' + request.form['inputAlbum'])
    return redirect('/')
Exemple #8
0
def toEdit():
    if request.method == 'POST':
        action = DB()
        action.toEditImageByImageId(request.form['inputImage'], session['id'])
        flash('Image marked to be edited.', 'success')
        if request.form['inputZoom'] == str(1):
            return redirect('/album/' + request.form['inputAlbum'] + '/' +
                            request.form['inputImage'])
        return redirect('/album/' + request.form['inputAlbum'])
    return redirect('/')
Exemple #9
0
def unstar():
    if request.method == 'POST':
        action = DB()
        action.unstarImageByImageId(request.form['inputImage'], session['id'])
        flash('Image unstarred.', 'warning')
        if request.form['inputZoom'] == str(1):
            return redirect('/album/' + request.form['inputAlbum'] + '/' +
                            request.form['inputImage'])
        return redirect('/album/' + request.form['inputAlbum'])
    return redirect('/')
Exemple #10
0
def createFolderAction():
    if request.method == 'POST' and session.get('active'):
        string = request.form['inputFolderName']
        action = DB()
        if request.form['inputUser']:
            user_id = request.form['inputUser']
        else:
            user_id = session['id']
        action.createFolder(user_id, string)
        flash('Folder created', 'success')
    return redirect('/')
Exemple #11
0
def unToEdit():
    if request.method == 'POST':
        action = DB()
        action.unToEditImageByImageId(request.form['inputImage'],
                                      session['id'])
        flash('Image removed from \"to be edited\".', 'warning')
        if request.form['inputZoom'] == str(1):
            return redirect('/album/' + request.form['inputAlbum'] + '/' +
                            request.form['inputImage'])
        return redirect('/album/' + request.form['inputAlbum'])
    return redirect('/')
Exemple #12
0
def feature():
    if request.method == 'POST':
        action = DB()
        action.setFeatureImageByFolderId(session['id'],
                                         request.form['inputImage'],
                                         request.form['inputAlbum'])
        flash('Image marked as album feature image.', 'success')
        if request.form['inputZoom'] == str(1):
            return redirect('/album/' + request.form['inputAlbum'] + '/' +
                            request.form['inputImage'])
        return redirect('/album/' + request.form['inputAlbum'])
    return redirect('/')
Exemple #13
0
def index(message=None, type='info'):
    if session.get('active'):
        repository = Repository()
        action = DB()
        user_id = session['id']
        # folders = action.getFoldersByUserId(session['id'])
        foldersFeatures = action.getFoldersByUserIdWithFeatureImage(
            session['id'])
        return (render_template('core/index.html',
                                mainFolder=user_id,
                                foldersFeatures=foldersFeatures,
                                active=False))
    else:
        if message:
            flash(message, type)
        return render_template('core/signin.html')
Exemple #14
0
def upload():
    if request.method == 'POST':
        image_files = request.files.getlist('images')
        for image_file in image_files:
            try:
                action = DB()
                if image_file and allowed_file(image_file.filename):
                    folder_id = request.form['inputFolder']
                    user_id = action.getUserIdByFolderId(folder_id)
                    # user_folder = action.getUserFolderByFolderId(folder_id)
                    File().saveImage(image_file, folder_id, user_id,
                                     request.form['inputEditTag'])
            except Exception as e:
                flash(image_file.filename + ' is an invalid file type. ' + e,
                      'danger')
    return redirect('/uploadimages')
Exemple #15
0
def inject_stuff():
    action = DB()
    if session.get('id'):
        user_id = session['id']
        folders = action.getFoldersByUserId(session['id'])
        tagCounts = {}
        tagCounts['starred'] = action.getStarredImageCountByUserId(user_id)
        tagCounts['toedit'] = action.getToEditImageCountByUserId(user_id)
        tagCounts['edited'] = action.getEditedImageCountByUserId(user_id)
        tagCounts['public'] = action.getPublicImageCountByUserId(user_id)
        tagCounts['deleted'] = action.getDeletedImageCountByUserId(user_id)
        return {
            'now': datetime.utcnow(),
            'tagCounts': tagCounts,
            'folders': folders
        }
    return {'now': datetime.utcnow(), 'tagCounts': 0}
Exemple #16
0
def signinAction(email=None, password=None):
    if request.method == 'POST' or (email and password):
        action = DB()
        email = request.form['inputEmail']
        password = request.form['inputPassword']
        if action.validateCreds(email, password):
            session['active'] = True
            userInfo = action.getUserInfoByEmail(email)
            user = User(userInfo[0], userInfo[1], userInfo[2])
            session['first'] = user.first
            session['last'] = user.last
            session['email'] = user.email
            # session['folder'] = user.folder
            user_id = action.getUserIdByEmail(email)
            session['folders'] = action.getFoldersByUserId(user_id)
            session['id'] = user_id
            action.recordLogin(user_id)
        else:
            flash('Email and password don\'t match', 'danger')
            return render_template('core/signin.html')
    return redirect('/')
Exemple #17
0
def resetPasswordAction():
    if request.method == 'POST':
        action = DB()
        newPassword = request.form['inputNewPassword']
        confirmNewPassword = request.form['confirmNewPassword']
        hash = request.form['inputHash']
        if not action.checkPasswordResetHash(hash):
            flash('Password reset is no longer valid', 'danger')
            return redirect('/')
        if newPassword != confirmNewPassword:
            flash('Passwords don\'t match', 'danger')
            return render_template('core/register.html')
        if len(newPassword) < 6:
            flash('Password too short', 'danger')
            return render_template('core/register.html')
        action.resetPassword(newPassword, hash)
        email = action.getUserEmailByUserId(
            action.getUserIdByPasswordHash(hash))
        flash('Password has been successfully updated.', 'success')
        # signinAction(email, newPassword)
    return redirect('/signin')
Exemple #18
0
def signout():
    action = DB()
    action.recordLogout(session['id'])
    session.clear()
    flash('Signed out, see you next time!', 'success')
    return redirect('/')
Exemple #19
0
def deleteUser():
    if request.method == 'POST' and session.get('id') == 1:
        action = DB()
        action.deleteUserById(request.form['inputUserId'])
        return redirect('/user-list')
Exemple #20
0
def uploadimages():
    action = DB()
    users = action.getUserWithFolderList()
    return render_template('core/uploadimage.html',
                           users=users,
                           active='uploadImages')
Exemple #21
0
def folder(user_id=None, album=None, image_id=None):
    if session.get('active'):
        action = DB()
        if album:
            user_id = session['id']
            hideFolders = True
            zoomImage = False
            active = str(album)
            images = False
            nextImage = False
            previousImage = False
            showFeatureFlag = False
            if not image_id:
                action.logAction(user_id,
                                 app.config['ACTIVITY_FOLDER_VIEW'],
                                 image_id=None,
                                 folder_id=album)
            if album == 'starred':
                albumName = 'Starred'
                images = action.getStarredImagesByUserID(user_id)
            elif album == 'toedit':
                albumName = 'To Edit'
                images = action.getToEditImagesByUserID(user_id)
            elif album == 'edited':
                albumName = 'Edited'
                images = action.getEditedImagesByUserID(user_id)
            elif album == 'public':
                albumName = 'Public'
                images = action.getPublicImagesByUserID(user_id)
            elif album == 'deleted':
                albumName = 'Deleted'
                images = action.getDeletedImagesByUserID(user_id)
            elif album:
                active = int(album)
                showFeatureFlag = True
                albumName = action.getFoldersLabelByID(album)
                images = action.getImagesByFolderId(album)
            if image_id:
                zoomImage = action.getImageByImageAndUserId(image_id, user_id)
                action.logAction(user_id, app.config['ACTIVITY_VIEW_ZOOMED'],
                                 image_id, album)
                if images and zoomImage:
                    if zoomImage in images:
                        imageLocation = images.index(zoomImage)
                        if imageLocation == len(images) - 1:
                            nextImage = False
                        else:
                            nextImage = action.getImageByImageAndUserId(
                                images[imageLocation + 1][1], user_id)
                        if imageLocation == 0:
                            previousImage = False
                        else:
                            previousImage = action.getImageByImageAndUserId(
                                images[imageLocation - 1][1], user_id)

            return (render_template('core/index.html',
                                    showFeatureFlag=showFeatureFlag,
                                    nextImage=nextImage,
                                    previousImage=previousImage,
                                    zoomImage=zoomImage,
                                    hideFolders=hideFolders,
                                    albumName=albumName,
                                    images=images,
                                    active=active))
    return index('You must be signed in to see this page', 'warning')
Exemple #22
0
def emptyTrash():
    action = DB()
    action.emptyTrashByUserId(session['id'])
    return redirect('/')