Resolved code formatting change requests
This commit is contained in:
parent
bedc03b18f
commit
9c13c6ae56
6 changed files with 37 additions and 30 deletions
|
@ -1,13 +1,11 @@
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from nacl import pwhash
|
||||||
from nacl.exceptions import InvalidkeyError
|
from nacl.exceptions import InvalidkeyError
|
||||||
|
|
||||||
from szurubooru import config, model, errors, db
|
from szurubooru import config, model, errors, db
|
||||||
from szurubooru.func import util
|
from szurubooru.func import util
|
||||||
from nacl import pwhash
|
|
||||||
|
|
||||||
|
|
||||||
RANK_MAP = OrderedDict([
|
RANK_MAP = OrderedDict([
|
||||||
|
|
|
@ -243,8 +243,10 @@ def update_user_password(user: model.User, password: str) -> None:
|
||||||
raise InvalidPasswordError(
|
raise InvalidPasswordError(
|
||||||
'Password must satisfy regex %r.' % password_regex)
|
'Password must satisfy regex %r.' % password_regex)
|
||||||
user.password_salt = auth.create_password()
|
user.password_salt = auth.create_password()
|
||||||
hash, revision = auth.get_password_hash(user.password_salt, password)
|
password_hash, revision = auth.get_password_hash(
|
||||||
user.password_hash = hash
|
user.password_salt,
|
||||||
|
password)
|
||||||
|
user.password_hash = password_hash
|
||||||
user.password_revision = revision
|
user.password_revision = revision
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ def run_migrations_offline():
|
||||||
url=url,
|
url=url,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
literal_binds=True,
|
literal_binds=True,
|
||||||
compare_type=True
|
compare_type=True)
|
||||||
)
|
|
||||||
|
|
||||||
with alembic.context.begin_transaction():
|
with alembic.context.begin_transaction():
|
||||||
alembic.context.run_migrations()
|
alembic.context.run_migrations()
|
||||||
|
@ -61,8 +60,7 @@ def run_migrations_online():
|
||||||
alembic.context.configure(
|
alembic.context.configure(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
compare_type=True
|
compare_type=True)
|
||||||
)
|
|
||||||
|
|
||||||
with alembic.context.begin_transaction():
|
with alembic.context.begin_transaction():
|
||||||
alembic.context.run_migrations()
|
alembic.context.run_migrations()
|
||||||
|
|
|
@ -47,14 +47,17 @@ class User(Base):
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.alter_column('user', 'password_hash',
|
op.alter_column(
|
||||||
existing_type=sa.VARCHAR(length=64),
|
'user',
|
||||||
type_=sa.Unicode(length=128),
|
'password_hash',
|
||||||
existing_nullable=False)
|
existing_type=sa.VARCHAR(length=64),
|
||||||
op.add_column('user', sa.Column('password_revision',
|
type_=sa.Unicode(length=128),
|
||||||
sa.SmallInteger(),
|
existing_nullable=False)
|
||||||
nullable=True,
|
op.add_column('user', sa.Column(
|
||||||
default=0))
|
'password_revision',
|
||||||
|
sa.SmallInteger(),
|
||||||
|
nullable=True,
|
||||||
|
default=0))
|
||||||
|
|
||||||
session = sa.orm.session.Session(bind=op.get_bind())
|
session = sa.orm.session.Session(bind=op.get_bind())
|
||||||
if session.query(User).count() >= 0:
|
if session.query(User).count() >= 0:
|
||||||
|
@ -69,13 +72,18 @@ def upgrade():
|
||||||
session.flush()
|
session.flush()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
op.alter_column('user', 'password_revision',
|
op.alter_column(
|
||||||
existing_nullable=True, nullable=False)
|
'user',
|
||||||
|
'password_revision',
|
||||||
|
existing_nullable=True,
|
||||||
|
nullable=False)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.alter_column('user', 'password_hash',
|
op.alter_column(
|
||||||
existing_type=sa.Unicode(length=128),
|
'user',
|
||||||
type_=sa.VARCHAR(length=64),
|
'password_hash',
|
||||||
existing_nullable=False)
|
existing_type=sa.Unicode(length=128),
|
||||||
|
type_=sa.VARCHAR(length=64),
|
||||||
|
existing_nullable=False)
|
||||||
op.drop_column('user', 'password_revision')
|
op.drop_column('user', 'password_revision')
|
||||||
|
|
|
@ -25,8 +25,8 @@ class User(Base):
|
||||||
name = sa.Column('name', sa.Unicode(50), nullable=False, unique=True)
|
name = sa.Column('name', sa.Unicode(50), nullable=False, unique=True)
|
||||||
password_hash = sa.Column('password_hash', sa.Unicode(128), nullable=False)
|
password_hash = sa.Column('password_hash', sa.Unicode(128), nullable=False)
|
||||||
password_salt = sa.Column('password_salt', sa.Unicode(32))
|
password_salt = sa.Column('password_salt', sa.Unicode(32))
|
||||||
password_revision = sa.Column('password_revision', sa.SmallInteger,
|
password_revision = sa.Column(
|
||||||
default=0, nullable=False)
|
'password_revision', sa.SmallInteger, default=0, nullable=False)
|
||||||
email = sa.Column('email', sa.Unicode(64), nullable=True)
|
email = sa.Column('email', sa.Unicode(64), nullable=True)
|
||||||
rank = sa.Column('rank', sa.Unicode(32), nullable=False)
|
rank = sa.Column('rank', sa.Unicode(32), nullable=False)
|
||||||
avatar_style = sa.Column(
|
avatar_style = sa.Column(
|
||||||
|
|
|
@ -115,11 +115,12 @@ def config_injector():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_factory():
|
def user_factory():
|
||||||
def factory(name=None,
|
def factory(
|
||||||
rank=model.User.RANK_REGULAR,
|
name=None,
|
||||||
email='dummy',
|
rank=model.User.RANK_REGULAR,
|
||||||
password_salt=None,
|
email='dummy',
|
||||||
password_hash=None):
|
password_salt=None,
|
||||||
|
password_hash=None):
|
||||||
user = model.User()
|
user = model.User()
|
||||||
user.name = name or get_unique_name()
|
user.name = name or get_unique_name()
|
||||||
user.password_salt = password_salt or 'dummy'
|
user.password_salt = password_salt or 'dummy'
|
||||||
|
|
Loading…
Reference in a new issue