mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-16 00:09:05 +00:00
Add ReCaptcha to upload page if user is not logged in.
Bring back CSRF to upload form (Use the upload API)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import flask
|
||||
from nyaa import db, app
|
||||
from nyaa.models import User
|
||||
from nyaa import bencode, utils, models
|
||||
@@ -15,6 +16,7 @@ from wtforms.widgets import Select as SelectWidget
|
||||
from wtforms.widgets import html_params, HTMLString
|
||||
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
from flask_wtf.recaptcha.validators import Recaptcha as RecaptchaValidator
|
||||
|
||||
|
||||
class Unique(object):
|
||||
@@ -164,10 +166,6 @@ class EditForm(FlaskForm):
|
||||
|
||||
|
||||
class UploadForm(FlaskForm):
|
||||
|
||||
class Meta:
|
||||
csrf = False
|
||||
|
||||
torrent_file = FileField('Torrent file', [
|
||||
FileRequired()
|
||||
])
|
||||
@@ -179,6 +177,16 @@ class UploadForm(FlaskForm):
|
||||
'%(max)d at most.')
|
||||
])
|
||||
|
||||
if app.config['USE_RECAPTCHA']:
|
||||
# Captcha only for not logged in users
|
||||
_recaptcha_validator = RecaptchaValidator()
|
||||
|
||||
def _validate_recaptcha(form, field):
|
||||
if not flask.g.user:
|
||||
return UploadForm._recaptcha_validator(form, field)
|
||||
|
||||
recaptcha = RecaptchaField(validators=[_validate_recaptcha])
|
||||
|
||||
# category = SelectField('Category')
|
||||
category = DisabledSelectField('Category')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user