|
|
@@ -7,15 +7,16 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
from .models import User, Bookmark, Groups
|
|
|
from . import db
|
|
|
import string, secrets
|
|
|
-import csv, os
|
|
|
+import csv
|
|
|
import subprocess as sp
|
|
|
|
|
|
logic = Blueprint('logic', __name__)
|
|
|
|
|
|
+# User Home Profile
|
|
|
@logic.route('/', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def home():
|
|
|
-
|
|
|
+ # generate csv of bookmarks
|
|
|
def generate_csv():
|
|
|
header = ['name', 'link', 'group', 'status']
|
|
|
alphanumeric = string.ascii_letters + string.digits
|
|
|
@@ -27,11 +28,14 @@ def home():
|
|
|
for bg, bml in bb_dic.items():
|
|
|
for bm in bml:
|
|
|
writer.writerow([bm.name, bm.link, bg, bm.status])
|
|
|
- #cwd = os.getcwd()
|
|
|
- p1 = sp.run(f'curl --upload-file app/static/generated/{ralphanum}.csv https://transfer.raqnet.org/', shell=True, capture_output=True, text=True)
|
|
|
+ p1 = sp.run(f'curl --upload-file app/static/generated/{ralphanum}.csv https://transfer.raqnet.org/',
|
|
|
+ shell=True,
|
|
|
+ capture_output=True,
|
|
|
+ text=True
|
|
|
+ )
|
|
|
return redirect(p1.stdout, code=302)
|
|
|
- #return send_file(f'{cwd}/app/static/generated/{ralphanum}.csv', as_attachment=True, attachment_filename='test.csv')
|
|
|
|
|
|
+ # initialize dictionary of bookmarks and groups
|
|
|
# owned groups
|
|
|
bgroups = Groups.query.filter_by(owner=current_user.id).all()
|
|
|
# owned bookmarks
|
|
|
@@ -45,6 +49,7 @@ def home():
|
|
|
inter_list.append(bm)
|
|
|
bb_dic[bg.group] = inter_list
|
|
|
|
|
|
+ # request method
|
|
|
if request.method == "POST":
|
|
|
username = request.form.get('username')
|
|
|
passwd = request.form.get('password')
|
|
|
@@ -83,6 +88,7 @@ def home():
|
|
|
|
|
|
return render_template('home.html', user=current_user, bdic=bb_dic)
|
|
|
|
|
|
+# Public Bookmarks
|
|
|
@logic.route('/shared', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def shared():
|
|
|
@@ -103,7 +109,7 @@ def shared():
|
|
|
|
|
|
return render_template('shared.html', user=current_user, bdic=bb_dic)
|
|
|
|
|
|
-
|
|
|
+# Account management
|
|
|
@logic.route('/create', methods=['GET', 'POST'])
|
|
|
@login_required
|
|
|
def create():
|
|
|
@@ -120,7 +126,12 @@ def create():
|
|
|
if wlink and wname and wstatus:
|
|
|
if wgroup == 'cng-555' and ngroup != '':
|
|
|
wgroup = ngroup
|
|
|
- new_link = Bookmark(owner=current_user.id, status=wstatus, name=wname, group=wgroup, link=wlink)
|
|
|
+ new_link = Bookmark(owner=current_user.id,
|
|
|
+ status=wstatus,
|
|
|
+ name=wname,
|
|
|
+ group=wgroup,
|
|
|
+ link=wlink
|
|
|
+ )
|
|
|
group_check = Groups.query.filter_by(group=wgroup).first()
|
|
|
if not group_check:
|
|
|
new_group = Groups(owner=current_user.id, group=wgroup)
|
|
|
@@ -131,7 +142,6 @@ def create():
|
|
|
|
|
|
return render_template('create_bookmark.html', user=current_user, bgroups=bgroups)
|
|
|
|
|
|
-
|
|
|
@logic.route('/login', methods=['GET', 'POST'])
|
|
|
def login():
|
|
|
if request.method == 'POST':
|
|
|
@@ -187,7 +197,10 @@ def register():
|
|
|
flash('Your Passwords must match!', category='error')
|
|
|
else:
|
|
|
if len(pass_list) == 2:
|
|
|
- new_user = User(email=email, username=username, password=generate_password_hash(passwd_2, method='sha256'))
|
|
|
+ new_user = User(email=email,
|
|
|
+ username=username,
|
|
|
+ password=generate_password_hash(passwd_2, method='sha256')
|
|
|
+ )
|
|
|
db.session.add(new_user)
|
|
|
db.session.commit()
|
|
|
flash('Account Registration Successful!', category='success')
|