def add_profile_photos(): multimedia = '' if 'myfile' in request.files and request.files['myfile'].filename != '': multimedia = 'myfile' rem = 'cover' elif 'myfile1' in request.files and request.files['myfile1'].filename != '': multimedia = 'myfile1' rem = 'display' else: return render_template('access_denied.html', error_msg="Error Occurred!", title="Error") file = request.files[multimedia] extension = file.filename.split('.')[-1] if file and allowed_file(extension): filename = secure_filename(file.filename) file.save(os.path.join(BLOB, session['username'], 'images', filename)) prof = get_profile(session['username']) if os.path.exists( os.path.join(BLOB, session['username'], 'images', prof[rem])): os.remove( os.path.join(BLOB, session['username'], 'images', prof[rem])) res = prof_img_upd(session['username'], filename, rem) if not res: return render_template('access_denied.html', error_msg="Error Occurred!", title="Error") return redirect(url_for('profile'))
def edit_password(): if request.method == 'POST': prof = edit_pass_util(request) if prof['new_pass'] != prof['con_pass']: return render_template('access_denied.html', error_msg="Passwords Don't match!", title="Error") if prof['cur_pass'] != get_password(session['username']): return render_template( 'access_denied.html', error_msg="Current Password entered is wrong!", title="Error") if update_password(session['username'], prof['new_pass']): return redirect(url_for('profile')) else: return render_template( 'access_denied.html', error_msg="Error Occurred while updating Password", title="Error") if request.method == 'GET': res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occurred while fetching Profile Details", title="Error") return render_template('edit-password.html', profile=res, title="Edit Profile") return render_template('access_denied.html', error_msg="wrong method Invocation", title="Error")
def profile(): res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occured while fetching Profile Details", title="Error") return render_template('profile.html', profile=res, title="Profile")
def search(ids): print("GET", ids) to_search = ids.split(',') to_search = [id.strip() for id in to_search] print(to_search) profiles = [] for id in to_search: time1 = time.time() profile = get_profile(id) if profile is None: # fazer pedido à API print("não tenho na BD, vou buscar à API") apiRetrieval, new_profile, errors = get_infos(id) # se for chamado com sucesso a API: if new_profile: profiles.append(new_profile) insert_profile(new_profile) if 'publications' in new_profile: num_pubs = len(new_profile['publications']) benchmarking_db_data = { 'type': 'api', 'time': apiRetrieval, 'num_pubs': num_pubs, 'errors': errors } insert_benchmark(benchmarking_db_data) # se der erro: else: profiles.append({'id': id, 'error': 'Something went wrong.'}) else: dbRetrieval = time.time() - time1 print("tenho na db") if 'publications' in profile: num_pubs = len(profile['publications']) benchmarking_db_data = { 'type': 'db', 'time': dbRetrieval, 'num_pubs': num_pubs } insert_benchmark(benchmarking_db_data) profiles.append(profile) return render_template('profile.html', profiles=profiles)
def delete_post(): if request.method == 'POST': folder = request.form['folder'] filename = request.form['filename'] if os.path.exists( os.path.join(BLOB, session['username'], 'posts', folder + 's', filename)): os.remove( os.path.join(BLOB, session['username'], 'posts', folder + 's', filename)) else: return render_template('access_denied.html', error_msg="File does not exist locally", title="Error") query = {"email": session['username']} result = db['user'].find_one(query) if bool(result): res = db['user'].update_one( {"email": session['username']}, {"$pull": { "posts": { 'post_name': filename } }}) else: return render_template( 'access_denied.html', error_msg="File does not exist in mongodb database", title="Error") posts = get_posts(session['username']) res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occured while fetching Profile Details", title="Error") return render_template('home.html', posts=posts, profile=res, msg="Post Successfully deleted!", search=False, title="Home") return render_template('access_denied.html', error_msg="Delete Post Method is not POST", title="Error")
def display_profile(): username = request.args.get('username') res = get_profile(username) msg = "User Profile: " + username res['interest'] = ', '.join(res['interest']) res['language'] = ', '.join(res['language']) if not res: return render_template( 'access_denied.html', error_msg="Error Occurred while fetching Profile Details", title="Error") return render_template('display_profile.html', profile=res, title="Display Profile", msg=msg)
def home(): if session['isSponsor'] == 1: posts, timer = get_sponser_timeline() return render_template('sponsor.html', search=False, posts=posts, title="Home", timer=timer) else: res = get_profile(session['username']) posts = get_posts(session['username']) return render_template('home.html', posts=posts, profile=res, search=False, title="Home")
def login(): if request.method == 'POST': result, password, username, wallet_address = login_util(request) if result: otp_secret = get_otp_secret(username) if result['password'] != password: return render_template( 'access_denied.html', error_msg= "Password doesn't match. Please go back and re-enter the password!", title="Error") if not verify_totp(request.form['token'], otp_secret): return render_template( 'access_denied.html', error_msg="MFA Failed, Please go back and Retry!", title="Error") session['username'] = username session['wallet_address'] = wallet_address res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error occurred while fetching Profile Details", title="Error") if result['isSponsor'] == 1: session['isSponsor'] = 1 posts, timer = get_sponser_timeline() return render_template('sponsor.html', search=False, posts=posts, title="Home", timer=timer) else: session['isSponsor'] = 0 posts = get_posts(username) return render_template('home.html', posts=posts, profile=res, search=False) return render_template('access_denied.html', error_msg="Mail Doesn't exists!", title="Error") return render_template('landing.html', title="Login Page")
def filters(): val = request.args.get('val') if session['isSponsor'] == 1: posts, timer = get_sponser_timeline() return render_template('sponsor.html', search=False, posts=posts, title="Home", filters=val, timer=timer) else: res = get_profile(session['username']) posts = get_posts(session['username']) return render_template('home.html', posts=posts, profile=res, search=False, title="Home", filters=val)
def documents(): if request.method == 'GET': res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occurred while fetching Profile Details", title="Error") if os.path.exists( os.path.join(BLOB, session['username'], 'posts', 'documents')): files = os.listdir( os.path.join(BLOB, session['username'], 'posts', 'documents')) else: files = [] return render_template('documents.html', profile=res, title="Documents", files=files, email=session['username']) return render_template('access_denied.html', error_msg="wrong method Invocation", title="Error")
def edit_language(): if request.method == 'POST': lan = edit_lan_int_util(request) if update_language(session['username'], lan): return redirect(url_for('profile')) else: return render_template( 'access_denied.html', error_msg="Error Occurred while updating Languages", title="Error") if request.method == 'GET': res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occurred while fetching Profile Details", title="Error") return render_template('edit-language.html', profile=res, title="Edit Profile") return render_template('access_denied.html', error_msg="wrong method Invocation", title="Error")
def add_post(): res = get_profile(session['username']) if not res: return render_template( 'access_denied.html', error_msg="Error Occurred while fetching Profile Details", title="Error") if request.method == 'POST': # check if the post request has the file part post_headline = request.form.get('headline') multimedia = '' folder_name = '' posts = '' if 'image' in request.files and request.files['image'].filename != '': multimedia = 'image' folder_name = 'images' elif 'audio' in request.files and request.files['audio'].filename != '': multimedia = 'audio' folder_name = 'audios' elif 'video' in request.files and request.files['video'].filename != '': multimedia = 'video' folder_name = 'videos' elif 'document' in request.files and request.files[ 'document'].filename != '': multimedia = 'document' folder_name = 'documents' else: flash('No file selected for uploading') return redirect(request.url) file = request.files[multimedia] extension = file.filename.split('.')[-1] if file and allowed_file(extension): filename = secure_filename(file.filename) file.save( os.path.join(BLOB, session['username'], 'posts', folder_name, filename)) post_info = { "post_type": multimedia, "post_name": filename, "post_headline": post_headline, "base_price": request.form.get('base_price'), "bid_price": [], "bidding_person": [], "first_bidding_time": "N/A", "bidding_status": "open", "date_time_added": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "transaction_hash": "N/A" } str = session['username'] + "Patrons Pool Portal" + post_headline vpn = hashlib.sha256(str.encode()) patent_info = { "vpn": vpn.hexdigest(), "headline": post_headline, "product_owners": [] } patent_info['product_owners'].append({ 'type': 'user', 'username': session['username'] }) store_posts(post_info) store_patent(patent_info) posts = get_posts(session['username']) # searches for dockerfile in the extracted folder # call this function after the user presses on the submit button or so # The below mentioned is the mailing functionality, Creates a separate thread and triggers the emails to all the sponsors thread = Thread(target=mail_sponsers_when_a_post_is_added, args=[app, session['username']]) thread.start() else: return render_template( "home.html", search=False, posts=posts, profile=res, msg='Allowed file types are mp4, mp3, png, jpg, jpeg, gif', title="Home") return render_template("home.html", search=False, posts=posts, profile=res, msg='Added Successfully! :-D', title="Home")