Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
def explore():
    page = request.args.get("page", 1, type=int)
    posts_per_page = app.config["POSTS_PER_PAGE"]
    all_posts = get_posts()
    posts = all_posts[(page - 1) * posts_per_page:page * posts_per_page]
    next_url = url_for("explore", page=page+1)\
            if (len(all_posts) > page*posts_per_page) else None
    prev_url = url_for("explore", page=page-1)\
            if (page-1 > 0) else None
    return render_template("index.html",
                           title="Explore",
                           posts=posts,
                           next_url=next_url,
                           prev_url=prev_url)
Ejemplo n.º 3
0
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")
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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")