Resolved code formatting change requests

This commit is contained in:
ReAnzu 2018-03-07 19:32:28 -06:00
parent bedc03b18f
commit 9c13c6ae56
6 changed files with 37 additions and 30 deletions

View file

@ -1,13 +1,11 @@
from typing import Tuple
import hashlib
import random
from collections import OrderedDict
from nacl import pwhash
from nacl.exceptions import InvalidkeyError
from szurubooru import config, model, errors, db
from szurubooru.func import util
from nacl import pwhash
RANK_MAP = OrderedDict([

View file

@ -243,8 +243,10 @@ def update_user_password(user: model.User, password: str) -> None:
raise InvalidPasswordError(
'Password must satisfy regex %r.' % password_regex)
user.password_salt = auth.create_password()
hash, revision = auth.get_password_hash(user.password_salt, password)
user.password_hash = hash
password_hash, revision = auth.get_password_hash(
user.password_salt,
password)
user.password_hash = password_hash
user.password_revision = revision

View file

@ -38,8 +38,7 @@ def run_migrations_offline():
url=url,
target_metadata=target_metadata,
literal_binds=True,
compare_type=True
)
compare_type=True)
with alembic.context.begin_transaction():
alembic.context.run_migrations()
@ -61,8 +60,7 @@ def run_migrations_online():
alembic.context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)
compare_type=True)
with alembic.context.begin_transaction():
alembic.context.run_migrations()

View file

@ -47,14 +47,17 @@ class User(Base):
def upgrade():
op.alter_column('user', 'password_hash',
existing_type=sa.VARCHAR(length=64),
type_=sa.Unicode(length=128),
existing_nullable=False)
op.add_column('user', sa.Column('password_revision',
sa.SmallInteger(),
nullable=True,
default=0))
op.alter_column(
'user',
'password_hash',
existing_type=sa.VARCHAR(length=64),
type_=sa.Unicode(length=128),
existing_nullable=False)
op.add_column('user', sa.Column(
'password_revision',
sa.SmallInteger(),
nullable=True,
default=0))
session = sa.orm.session.Session(bind=op.get_bind())
if session.query(User).count() >= 0:
@ -69,13 +72,18 @@ def upgrade():
session.flush()
session.commit()
op.alter_column('user', 'password_revision',
existing_nullable=True, nullable=False)
op.alter_column(
'user',
'password_revision',
existing_nullable=True,
nullable=False)
def downgrade():
op.alter_column('user', 'password_hash',
existing_type=sa.Unicode(length=128),
type_=sa.VARCHAR(length=64),
existing_nullable=False)
op.alter_column(
'user',
'password_hash',
existing_type=sa.Unicode(length=128),
type_=sa.VARCHAR(length=64),
existing_nullable=False)
op.drop_column('user', 'password_revision')

View file

@ -25,8 +25,8 @@ class User(Base):
name = sa.Column('name', sa.Unicode(50), nullable=False, unique=True)
password_hash = sa.Column('password_hash', sa.Unicode(128), nullable=False)
password_salt = sa.Column('password_salt', sa.Unicode(32))
password_revision = sa.Column('password_revision', sa.SmallInteger,
default=0, nullable=False)
password_revision = sa.Column(
'password_revision', sa.SmallInteger, default=0, nullable=False)
email = sa.Column('email', sa.Unicode(64), nullable=True)
rank = sa.Column('rank', sa.Unicode(32), nullable=False)
avatar_style = sa.Column(

View file

@ -115,11 +115,12 @@ def config_injector():
@pytest.fixture
def user_factory():
def factory(name=None,
rank=model.User.RANK_REGULAR,
email='dummy',
password_salt=None,
password_hash=None):
def factory(
name=None,
rank=model.User.RANK_REGULAR,
email='dummy',
password_salt=None,
password_hash=None):
user = model.User()
user.name = name or get_unique_name()
user.password_salt = password_salt or 'dummy'