コード例 #1
0
ファイル: settings.py プロジェクト: tofighi/iShare
def settings(user):
    sett = global_settings.find().next(
    ) if global_settings.count() != 0 else {}
    admin_email = sett.get('email', None)
    web_title = sett.get('title', None)

    # check if user is an admin
    admin = global_database.find_one(ids['user'], username=user, fsr=True)

    if admin is not None:
        # admin saving changes
        if request.args.get('wave') is not None:
            # update the global setting
            global_settings.update({}, {
                '$set': {
                    'wave': int(request.args['wave']),
                    'diss': int(request.args['dis']),
                    'email': request.args['admin_email'],
                    'email_pass': request.args['admin_pass'],
                    'title': request.args['web_title'],
                    'max_tags': request.args['max_tags']
                }
            })

            flash('Successfully saved changes')

        return render_template('pages/settings.html',
                               set=sett,
                               email=admin_email,
                               title=web_title)
    else:
        flash("page dose not exist....")
        return redirect('/')
コード例 #2
0
ファイル: views.py プロジェクト: tofighi/iShare
def welcome():
    #get settings
    sett = global_settings.find().next()

    return render_template('pages/landingpage.html',
                           session=session,
                           page=0,
                           set=sett)
コード例 #3
0
ファイル: admin_email.py プロジェクト: tofighi/iShare
    @property
    def admin(self):
        return self._admin
    @property
    def password(self):
        return self._password

    @admin.setter
    def admin(self, value):
        self._admin = value
    @password.setter
    def password(self, value):
        self._password = value

# write username and password here
username = global_settings.find().next().get('email','')
password = global_settings.find().next().get('email_pass','')


# to = "*****@*****.**"
# msg = "Enter_Message"

# get current location
__location__ = os.path.realpath(
    os.path.join(os.getcwd(), os.path.dirname(__file__)))

# attach the file html
attachment = os.path.join(__location__,"email-content.html")

with open(attachment, 'r') as file:
    attachment = file.read()
コード例 #4
0
def edit_repo(admin, user, title):
    # check if user is admin
    administrator = global_database.find_one(ids['user'], username=admin)
    # admin editing the paper
    if request.method == "GET":
        # check if user is admin
        if administrator is not None \
                and session['username'] == admin:
            # find repo
            query = global_database.find_one(ids['repo'],
                                             username=user,
                                             title=title)
            # find section
            sections = global_database.query(ids['section'],
                                             limit=global_database.count(
                                                 ids['section']))

            return render_template('pages/edit.html',
                                   query=query,
                                   all_sections=sections)

        else:
            flash("page does not exist")
            return redirect(url_for('all_time'))

    # admin saved edited paper
    else:
        # get date stars and avatar and validate data
        date, stars, avatar, pdf = validate(request)

        # Api maximum limit has reached
        if isinstance(stars, dict) or isinstance(avatar, dict):
            # Flash the message
            flash(stars)
            # redirect to homepage
            return redirect('/')

        # get tags
        tags = str(request.form.get('tags'))
        tags = tags.split(';')
        tags.pop()

        max_tags = int(global_settings.find().next().get('max_tags', 5))

        # tag overload
        if len(tags) > max_tags:
            flash("Maximum Tags Reached")
            return redirect(
                url_for('edit_repo', admin=admin, user=user, title=title))

        heroku = True if "heroku" in request.form.get('deploy',
                                                      [None]) else False

        # get data from user
        content = {
            'username': user,
            'title': request.form['title'],
            'url_repo': request.form['repo'],
            'url_pdf': pdf,
            'date': f'{date}',
            'description': request.form['desc'],
            'star': stars,
            'avatar': avatar,
            'tags': tags,
            'section': request.form['section'],
            'heroku': heroku,
            'approved': True,
            'pending': False
        }
        # update the repo
        repos.replace_one({'username': user, 'title': title}, content, True)

        # show success
        flash("Successfully updated the paper")
        return redirect(f'/{user}/profile')
コード例 #5
0
def detail(user, title):
    # get global settings
    sett = global_settings.find().next()

    # get repo out of the database
    repo = global_database.find_one(ids['repo'], username=user, title=title)
    # get repo comments
    all_comments = global_database.find_one(ids['comments'], title=title)

    if repo is not None:
        # if comment section exist in the repo
        if all_comments is not None:
            all_comments = all_comments['comments']

        # make star human readable
        repo['star'] = "{:,}".format(repo['star'])

        # check if user is signed in
        if session.get('username') is not None:
            # user made comments
            if request.args.get('user') is not None:

                # if comment section exist
                if global_database.find_one(ids['comments'],
                                            title=title) is not None:
                    # get data
                    content = {
                        'username': request.args.get('user'),
                        'date': request.args.get('today'),
                        'comment': request.args.get('comment')
                    }
                    # then update the comment section
                    comments.update({'title': title},
                                    {'$push': {
                                        'comments': content
                                    }})
                    # send to ajax
                    return jsonify(content)
                else:
                    # get data
                    content = {
                        'username': request.args.get('user'),
                        'date': request.args.get('today'),
                        'comment': request.args.get('comment')
                    }
                    # insert to the first comment to the database
                    global_database.insert(ids['comments'],
                                           title=title,
                                           comments=[content])
                    # send to ajax
                    return jsonify(content)
        else:
            flash("sign in to leave a comment")
        return render_template('pages/detail.html',
                               repo=repo,
                               session=session,
                               comments=all_comments,
                               set=sett)
    else:
        flash("not found: " + title)
        return redirect('/')


# @socketio.on('message')
# def handleMessage(msg):
#     print(f"Message: {msg}")
#     send(msg, broadcast=True)
コード例 #6
0
ファイル: upload.py プロジェクト: tofighi/iShare
def upload(user):
    # get all sections
    sec = global_database.query(ids['section'],
                                limit=global_database.count(ids['section']))

    all_sections = []

    # append all sections
    for section in sec:
        all_sections.append(section)

    # validate if username is signed in
    if session.get('username') != None and session['username'] == user:

        # user is uploading a paper
        if request.method == "GET":
            return render_template('pages/upload.html',
                                   all_sections=all_sections)
        # user is submitting the paper
        else:
            # get date stars and avatar and validate data
            #check if user enter the correct information
            date, stars, avatar, pdf = validate(request)

            # Api maximum limit has reached
            if isinstance(stars, dict) or isinstance(avatar, dict):
                # Flash the message
                flash(stars)
                # redirect to homepage
                return redirect('/')

            # check if paper is valid
            if None in {date, stars, avatar, pdf}:

                flash("Could not upload paper")

                return redirect(url_for('upload', user=user))

            else:
                # get tags
                tags = str(request.form.get('tags'))
                tags = tags.split(';')
                tags.pop()

                max_tags = int(global_settings.find().next().get(
                    'max_tags', 5))
                # tag overload
                if len(tags) > max_tags:
                    flash("Maximum Tags Reached")
                    return redirect(url_for('upload', user=user))

                # check if title exist in the database
                if global_database.find_one(ids['repo'],
                    title=request.form['title']) is not None or \
                    any(char in request.form.get('title') for char in {'?', '!', '/', '\\', '<', '>'}):
                    flash(
                        "A Paper With The Same Title is Uploaded Or The Title Has Symbols In It"
                    )

                    return redirect(url_for('upload', user=user))

                else:

                    #TODO:// prevent html injection

                    # insert into the database
                    global_database.insert(
                        ids['repo'],
                        username=session['username'],
                        title=request.form['title'],
                        url_repo=request.form['repo'],
                        url_pdf=pdf,
                        date=f'{date}',
                        description=request.form['desc'],
                        star=stars,
                        avatar=avatar,
                        section=request.form['section'],
                        tags=tags,
                        pending=True,
                        approved=False,
                    )

                    # success flash popped up
                    flash("Paper Successfully Uploaded")
                    # redirect to the homepage
                    return redirect('/')

        # user entered the wrong url
    else:
        # wrong url entered
        flash('failure page does not exist')
        # redirect to the homepage
        return redirect('/')
コード例 #7
0
ファイル: views.py プロジェクト: tofighi/iShare
def search(repo):
    """
    search engine logic
    :param repo: search user, title ,tags or section
    :return: query result
    """
    # get settings
    sett = global_settings.find().next()

    #PAGE PAGINATION SETTINGS
    user = repo

    limit = int(request.args.get('limit', 10))
    offset = int(request.args.get('offset', 0))

    # regex pattern
    pattern = re.compile(repo, re.IGNORECASE)

    search_logic = {
        '$or': [{
            'title': pattern
        }, {
            'username': pattern
        }, {
            'section': pattern
        }],
        '$and': [{
            'approved': True
        }]
    }

    # get all liked repos or username and sort it deafeningly by the amount of repo star
    temp = repos.find(search_logic).sort('star', -1)
    if temp.count() != 0:
        if offset >= temp.count():
            offset = temp.count() - 1

        last_id = temp[offset]['star']

        if {'$gte': last_id} not in search_logic['$and']:
            search_logic['$and'].append({'star': {'$lte': last_id}})
        else:
            search_logic['$and']['star']['$lte'] = last_id

        search = repos.find(search_logic).sort('star', -1).limit(limit)

        # list of repositories
        repository = []

        # append the repos
        for repo in search:
            repository.append(repo)

    # if repos do not exist
    else:
        repository = None
        # then message the user
        flash("Could not find a result.....")

    #get the page
    page = request.args.get('page', 1)

    # render the landing page
    return render_template('pages/landingpage.html',
                           repositories=repository,
                           page=page,
                           user=user,
                           set=sett,
                           limit=limit,
                           offset=offset,
                           maxx=temp.count())