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 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([

View file

@ -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

View file

@ -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()

View file

@ -47,11 +47,14 @@ class User(Base):
def upgrade(): def upgrade():
op.alter_column('user', 'password_hash', op.alter_column(
'user',
'password_hash',
existing_type=sa.VARCHAR(length=64), existing_type=sa.VARCHAR(length=64),
type_=sa.Unicode(length=128), type_=sa.Unicode(length=128),
existing_nullable=False) existing_nullable=False)
op.add_column('user', sa.Column('password_revision', op.add_column('user', sa.Column(
'password_revision',
sa.SmallInteger(), sa.SmallInteger(),
nullable=True, nullable=True,
default=0)) default=0))
@ -69,12 +72,17 @@ 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(
'user',
'password_hash',
existing_type=sa.Unicode(length=128), existing_type=sa.Unicode(length=128),
type_=sa.VARCHAR(length=64), type_=sa.VARCHAR(length=64),
existing_nullable=False) existing_nullable=False)

View file

@ -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(

View file

@ -115,7 +115,8 @@ def config_injector():
@pytest.fixture @pytest.fixture
def user_factory(): def user_factory():
def factory(name=None, def factory(
name=None,
rank=model.User.RANK_REGULAR, rank=model.User.RANK_REGULAR,
email='dummy', email='dummy',
password_salt=None, password_salt=None,