예제 #1
0
def change():
    menu = viewMenu.catsMenu()
    if request.method == 'POST':
        # access post parameters
        old = request.form.get('oldpassword')
        new = request.form.get('newpassword')
        conf = request.form.get('confirmation')
        # see if new and confirmation password match
        if new != conf:
            return apology("New passord and confirmation don't match.")
        # query database to access user data
        row = mydb.execute("select * from users where id = ?",
                           (session['user_id'], ))
        oldhash = row[0]['hash']
        if not check_password_hash(oldhash, old):
            return apology('Current password is wrong.')
        newhash = generate_password_hash(new)
        # update database with new user password
        mydb.execute('update users set hash = ? where id = ?', (
            newhash,
            session['user_id'],
        ))
        return redirect(url_for('auth_bp.logout'))
    else:
        return render_template('change.html', menu=menu)
예제 #2
0
def create():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    listCats = list(map(lambda x: x['cat_name'], categories))
    if request.method == 'POST':
        # category always case independent
        category = request.form.get('category').lower()
        url = request.form.get('url')
        # see: https://www.urlencoder.io/python/
        url = quote(url)
        title = request.form.get('title')
        description = request.form.get('description')
        if category not in listCats:
            mydb.execute(
                'insert into categories(cat_name, user_id) values(?,?)',
                category, session['user_id'])
            mydb.execute(
                'insert into menu(cat_name,user_id,visible) values(?,?,?)',
                category, session['user_id'], 1)
        mydb.execute(
            '''insert into bookmarks(categ_name, user_id, url, title, description) 
                   values(?,?,?,?,?)''', category, session['user_id'], url,
            title, description)
        urlImage(mydb, url)
        flash(f"Bookmark added to category {category}")
        return redirect(url_for('index'))
    else:
        # print(listCats)
        return render_template('create.html', categories=listCats, menu=menu)
예제 #3
0
def rem_bookmark():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    bookmarks = build_bookmarks(mydb, categories)
    #print(bookmarks)
    flash('Select the bookmark you want to remove')
    return render_template('rem_bookmark.html', bookmarks=bookmarks, menu=menu)
예제 #4
0
def rem_cat():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    listCats = list(map(lambda x: x['cat_name'], categories))
    flash(
        'Warning: Removing a category implies deleting all bookmarks linked to it'
    )
    return render_template('rem_cat.html', categories=listCats, menu=menu)
예제 #5
0
def edit_id(id):
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    bid = int(id)
    rows = mydb.execute('select * from bookmarks where id = ? and user_id = ?',
                        bid, session['user_id'])
    listCats = list(map(lambda x: x['cat_name'], categories))
    html = render_template('edit_id.html',
                           row=rows[0],
                           categories=listCats,
                           menu=menu)
    return html
예제 #6
0
def import_bms():
    menu = viewMenu.catsMenu()
    known_cats = mydb.execute(
        'select cat_name from categories where user_id = ?',
        (session['user_id'], ))
    listCats = list(map(lambda x: x['cat_name'], known_cats))
    if request.method == 'POST':
        categories = []
        urls = mydb.execute('select url from bookmarks where user_id = ?',
                            (session['user_id'], ))
        listUrls = list(map(lambda x: x['url'], urls))
        # see: https://www.kite.com/python/docs/werkzeug.FileStorage#:~:text=The%20%3Aclass%3A%60FileStorage%60%20class,the%20long%20form%20%60%60storage.
        try:
            file = request.files['filename']
        except:
            return apology('Sorry, could not open the file')
        else:
            try:
                file_content = file.read().decode('utf-8')
            except UnicodeDecodeError:
                return apology('Sorry, this does not seem to be a text file.')
            else:
                # json -> python dictionary
                try:
                    bm_dict = json.loads(file_content)
                except:
                    return apology(
                        'Sorry, could not recognize this as a JSON file.')
                else:
                    # consider only bookmarks bar
                    # in the application, test if the if the key ['root']['bookmar_bar'] is defined!
                    try:
                        bm_dict = bm_dict['roots']['bookmark_bar']['children']
                    except:
                        return apology(
                            'Sorry, could not find bookmark_bar inside the file.'
                        )
                    else:
                        for child in bm_dict:
                            if child['type'] == 'url':
                                categories.append(processURL(child))
                            if child['type'] == 'folder':
                                categories += processFolder(child)
                        for category in categories:
                            print('category', category['category'].lower())
                            print('ListCats', listCats)
                            if category['category'].lower() not in listCats:
                                mydb.execute(
                                    'insert into categories(cat_name, user_id) values(?,?)',
                                    category['category'].lower(),
                                    session['user_id'])
                                mydb.execute(
                                    'insert into menu(cat_name,user_id,visible) values(?,?,?)',
                                    category['category'].lower(),
                                    session['user_id'], 1)
                                listCats.append(category['category'].lower())
                            if category['url'] in listUrls:
                                # print('updating bookmarks in import')
                                mydb.execute(
                                    '''update bookmarks set categ_name=?, 
                                     title = ?, description = ? 
                                     where user_id = ? and url = ?''',
                                    category['category'].lower(),
                                    category['title'], category['description'],
                                    session['user_id'], category['url'])
                            else:
                                mydb.execute(
                                    '''insert into bookmarks(categ_name, user_id, url, title, description) 
                                        values(?,?,?,?,?)''',
                                    category['category'].lower(),
                                    session['user_id'], category['url'],
                                    category['title'], category['description'])
                        return redirect(url_for('index'))
    else:
        return render_template('import.html', categories=listCats, menu=menu)
예제 #7
0
def index():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    bookmarks = build_bookmarks(mydb, categories)
    # print(bookmarks)
    return render_template('index-grid-css.html', bookmarks=bookmarks, menu=menu)
예제 #8
0
def readme():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    bookmarks = build_bookmarks(mydb, categories)
    return render_template('readme.html', bookmarks=bookmarks, menu=menu)
예제 #9
0
def hide_all():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    for cat in categories:
        viewMenu.setChecked(cat['cat_name'], False)
    return redirect(url_for('index'))
예제 #10
0
def edit():
    menu = viewMenu.catsMenu()
    categories = list(map(lambda x: {'cat_name': x['name']}, menu))
    bookmarks = build_bookmarks(mydb, categories)
    flash('Select the bookmark you want to edit')
    return render_template('edit.html', bookmarks=bookmarks, menu=menu)