Skip to content

Commit

Permalink
Don't use deprecated CSRF methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReverend403 committed Jul 2, 2019
1 parent f855a6a commit a16071d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/forms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@

class UploadForm(FlaskForm):
file = FileField(validators=[FileRequired()])

class Meta:
csrf = False
7 changes: 6 additions & 1 deletion app/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# along with pste. If not, see <https://www.gnu.org/licenses/>.

import os
from pathlib import Path

from flask import current_app as app
from sqlalchemy import func, event

from app import db
Expand All @@ -37,7 +39,10 @@ def path(self):
return f'{self.user.storage_directory()}/{self.slug}'

def response_mimetype(self):
# TODO: Implement sending of certain file types as text/plain.
extension = Path(self.path()).suffix
if extension and extension.lstrip('.') in app.config['PLAINTEXT_TYPES']:
return 'text/plain'

return self.server_mimetype


Expand Down
2 changes: 1 addition & 1 deletion app/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@login_required
@csrf.exempt
def upload():
form = UploadForm(request.files, csrf_enabled=False)
form = UploadForm(request.files)
if not form.validate_on_submit():
return jsonify({'errors': form.errors})

Expand Down

0 comments on commit a16071d

Please sign in to comment.