1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 14:40:00 +00:00

Fix cookies messing with cache

Change Display name to Torrent display name for clarity
This commit is contained in:
nyaadev 2017-05-13 19:26:43 +02:00
parent 4571b55fc9
commit 064c33ecf4
3 changed files with 22 additions and 12 deletions

View file

@ -13,6 +13,9 @@ app.config.from_object('config')
# Database # Database
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Don't refresh cookie each request
app.config['SESSION_REFRESH_EACH_REQUEST'] = False
# Debugging # Debugging
if app.config['DEBUG']: if app.config['DEBUG']:
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

View file

@ -124,9 +124,9 @@ class DisabledSelectField(SelectField):
class EditForm(FlaskForm): class EditForm(FlaskForm):
display_name = TextField('Display name', [ display_name = TextField('Torrent display name', [
Length(min=3, max=255, Length(min=3, max=255,
message='Torrent name must be at least %(min)d characters and %(max)d at most.') message='Torrent display name must be at least %(min)d characters long and %(max)d at most.')
]) ])
category = DisabledSelectField('Category') category = DisabledSelectField('Category')
@ -134,7 +134,7 @@ class EditForm(FlaskForm):
def validate_category(form, field): def validate_category(form, field):
cat_match = re.match(r'^(\d+)_(\d+)$', field.data) cat_match = re.match(r'^(\d+)_(\d+)$', field.data)
if not cat_match: if not cat_match:
raise ValidationError('You must select a category') raise ValidationError('Please select a category')
main_cat_id = int(cat_match.group(1)) main_cat_id = int(cat_match.group(1))
sub_cat_id = int(cat_match.group(2)) sub_cat_id = int(cat_match.group(2))
@ -142,7 +142,7 @@ class EditForm(FlaskForm):
cat = models.SubCategory.by_category_ids(main_cat_id, sub_cat_id) cat = models.SubCategory.by_category_ids(main_cat_id, sub_cat_id)
if not cat: if not cat:
raise ValidationError('You must select a proper category') raise ValidationError('Please select a proper category')
field.parsed_data = cat field.parsed_data = cat
@ -169,10 +169,10 @@ class UploadForm(FlaskForm):
FileRequired() FileRequired()
]) ])
display_name = TextField('Display name (optional)', [ display_name = TextField('Torrent display name (optional)', [
Optional(), Optional(),
Length(min=3, max=255, Length(min=3, max=255,
message='Torrent name must be at least %(min)d characters long and %(max)d at most.') message='Torrent display name must be at least %(min)d characters long and %(max)d at most.')
]) ])
# category = SelectField('Category') # category = SelectField('Category')
@ -181,7 +181,7 @@ class UploadForm(FlaskForm):
def validate_category(form, field): def validate_category(form, field):
cat_match = re.match(r'^(\d+)_(\d+)$', field.data) cat_match = re.match(r'^(\d+)_(\d+)$', field.data)
if not cat_match: if not cat_match:
raise ValidationError('You must select a category') raise ValidationError('Please select a category')
main_cat_id = int(cat_match.group(1)) main_cat_id = int(cat_match.group(1))
sub_cat_id = int(cat_match.group(2)) sub_cat_id = int(cat_match.group(2))
@ -189,7 +189,7 @@ class UploadForm(FlaskForm):
cat = models.SubCategory.by_category_ids(main_cat_id, sub_cat_id) cat = models.SubCategory.by_category_ids(main_cat_id, sub_cat_id)
if not cat: if not cat:
raise ValidationError('You must select a proper category') raise ValidationError('Please select a proper category')
field.parsed_data = cat field.parsed_data = cat

View file

@ -10,7 +10,7 @@ import config
import json import json
import re import re
from datetime import datetime from datetime import datetime, timedelta
import ipaddress import ipaddress
import os.path import os.path
import base64 import base64
@ -190,6 +190,10 @@ def before_request():
return logout() return logout()
flask.g.user = user flask.g.user = user
if not 'timeout' in flask.session or flask.session['timeout'] < datetime.now():
print("hio")
flask.session['timeout'] = datetime.now() + timedelta(days=7)
flask.session.permanent = True flask.session.permanent = True
flask.session.modified = True flask.session.modified = True
@ -348,6 +352,8 @@ def login():
flask.g.user = user flask.g.user = user
flask.session['user_id'] = user.id flask.session['user_id'] = user.id
flask.session.permanent = True
flask.session.modified = True
return flask.redirect(redirect_url()) return flask.redirect(redirect_url())
@ -388,6 +394,8 @@ def register():
db.session.commit() db.session.commit()
flask.g.user = user flask.g.user = user
flask.session['user_id'] = user.id flask.session['user_id'] = user.id
flask.session.permanent = True
flask.session.modified = True
return flask.redirect(redirect_url()) return flask.redirect(redirect_url())
return flask.render_template('register.html', form=form) return flask.render_template('register.html', form=form)
@ -418,7 +426,6 @@ def profile():
db.session.commit() db.session.commit()
flask.g.user = user flask.g.user = user
flask.session['user_id'] = user.id
return flask.render_template('profile.html', form=form) return flask.render_template('profile.html', form=form)