Ejemplo n.º 1
0
def submit_report(torrent_id):
    if not flask.g.user or flask.g.user.age < app.config[
            'RATELIMIT_ACCOUNT_AGE']:
        flask.abort(403)

    form = forms.ReportForm(flask.request.form)
    torrent = models.Torrent.by_id(torrent_id)
    if not torrent:
        flask.abort(404)
    if torrent.banned:
        flask.flash("The torrent you've tried to report is already banned.",
                    'danger')
        flask.abort(404)

    if flask.request.method == 'POST' and form.validate():
        report_reason = form.reason.data
        current_user_id = flask.g.user.id
        report = models.Report(torrent_id=torrent_id,
                               user_id=current_user_id,
                               reason=report_reason)

        db.session.add(report)
        db.session.commit()
        flask.flash('Successfully reported torrent!', 'success')
    elif len(form.reason.data) == 0:
        flask.flash('Please give a report reason!', 'danger')

    return flask.redirect(flask.url_for('torrents.view',
                                        torrent_id=torrent_id))
Ejemplo n.º 2
0
def submit_report(torrent_id):
    if not flask.g.user:
        flask.abort(403)

    form = forms.ReportForm(flask.request.form)

    if flask.request.method == 'POST' and form.validate():
        report_reason = form.reason.data
        current_user_id = flask.g.user.id
        report = models.Report(torrent_id=torrent_id,
                               user_id=current_user_id,
                               reason=report_reason)

        db.session.add(report)
        db.session.commit()
        flask.flash('Successfully reported torrent!', 'success')

    return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id))