Rename config user.min_length -> min_username_length.

master
voussoir 2018-04-15 14:32:18 -07:00
parent 21bd211889
commit 4434517c54
4 changed files with 16 additions and 8 deletions

View File

@ -42,7 +42,7 @@ FILENAME_BADCHARS = '\\/:*?<>|"'
# Note: Setting user_version pragma in init sequence is safe because it only
# happens after the out-of-date check occurs, so no chance of accidentally
# overwriting it.
DATABASE_VERSION = 13
DATABASE_VERSION = 14
DB_INIT = f'''
PRAGMA cache_size = 10000;
PRAGMA count_changes = OFF;
@ -305,10 +305,10 @@ DEFAULT_CONFIGURATION = {
},
'user': {
'min_length': 2,
'min_username_length': 2,
'min_password_length': 6,
'max_display_name_length': 24,
'max_length': 24,
'max_username_length': 24,
'valid_chars': string.ascii_letters + string.digits + '_-',
},

View File

@ -933,16 +933,16 @@ class PDBUserMixin:
raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length'])
def _assert_valid_username(self, username):
if len(username) < self.config['user']['min_length']:
if len(username) < self.config['user']['min_username_length']:
raise exceptions.UsernameTooShort(
username=username,
min_length=self.config['user']['min_length']
min_length=self.config['user']['min_username_length']
)
if len(username) > self.config['user']['max_length']:
if len(username) > self.config['user']['max_username_length']:
raise exceptions.UsernameTooLong(
username=username,
max_length=self.config['user']['max_length']
max_length=self.config['user']['max_username_length']
)
badchars = [c for c in username if c not in self.config['user']['valid_chars']]

View File

@ -48,7 +48,7 @@ def get_login():
response = flask.render_template(
'login.html',
session=session,
min_username_length=common.P.config['user']['min_length'],
min_username_length=common.P.config['user']['min_username_length'],
min_password_length=common.P.config['user']['min_password_length'],
)
return response

View File

@ -257,6 +257,14 @@ def upgrade_12_to_13(photodb):
cur.execute('DROP TABLE users_old')
cur.execute('PRAGMA foreign_keys = ON')
def upgrade_13_to_14(photodb):
'''
Rename user.min_length to min_username_length.
'''
photodb.config['user']['min_username_length'] = photodb.config['user'].pop('min_length')
photodb.config['user']['max_username_length'] = photodb.config['user'].pop('max_length')
photodb.save_config()
def upgrade_all(data_directory):
'''
Given the directory containing a phototagger database, apply all of the