add username

This commit is contained in:
Sorrel Bri 2019-10-05 23:57:36 -07:00
parent a2697b8a11
commit 257fd6a533
3 changed files with 36 additions and 6 deletions

View file

@ -0,0 +1,30 @@
"""empty message
Revision ID: 0e0f8ad1362d
Revises: 50aab465cf44
Create Date: 2019-10-05 23:21:57.620808
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0e0f8ad1362d'
down_revision = '50aab465cf44'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('username', sa.String(length=255), nullable=False))
op.create_unique_constraint(None, 'users', ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'users', type_='unique')
op.drop_column('users', 'username')
# ### end Alembic commands ###

View file

@ -39,7 +39,7 @@ def upgrade():
op.create_table('users', op.create_table('users',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('email', sa.String(length=255), nullable=False), sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('password', sa.Integer(length=255), nullable=False), sa.Column('password', sa.String(length=255), nullable=False),
sa.Column('registered_on', sa.DateTime(), nullable=False), sa.Column('registered_on', sa.DateTime(), nullable=False),
sa.Column('admin', sa.Boolean(), nullable=False), sa.Column('admin', sa.Boolean(), nullable=False),
sa.Column('rank', sa.Enum('D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10', 'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20', 'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', name='ranks'), nullable=True), sa.Column('rank', sa.Enum('D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10', 'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20', 'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', name='ranks'), nullable=True),

View file

@ -49,6 +49,7 @@ class User(db.Model):
__tablename__ = "users" __tablename__ = "users"
id = db.Column(db.Integer, primary_key=True, autoincrement=True) id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(255), unique=True, nullable=False, autoincrement=True)
email = db.Column(db.String(255), unique=True, nullable=False) email = db.Column(db.String(255), unique=True, nullable=False)
password = db.Column(db.String(255), nullable=False) password = db.Column(db.String(255), nullable=False)
registered_on = db.Column(db.DateTime, nullable=False) registered_on = db.Column(db.DateTime, nullable=False)
@ -57,14 +58,13 @@ class User(db.Model):
elo = db.Column(db.Integer) elo = db.Column(db.Integer)
rank_certainty = db.Column(db.Boolean, nullable=False, default=False) rank_certainty = db.Column(db.Boolean, nullable=False, default=False)
def __init__(self, email, password, admin=False,): def __init__(self, username, email, password, rank='RU', admin=False):
print('user init') self.username = username
self.email = email self.email = email
print('user email init')
self.password = bcrypt.generate_password_hash( self.password = bcrypt.generate_password_hash(
password, 13 password, 13
).decode() ).decode()
print('user password init') self.rank = rank
self.registered_on = datetime.datetime.now() self.registered_on = datetime.datetime.now()
self.admin = admin self.admin = admin
@ -106,7 +106,7 @@ class UserSchema(ma.ModelSchema):
class Meta: class Meta:
fields = ( fields = (
'id', 'id',
'name', 'username',
'email', 'email',
'registered_on', 'registered_on',
'rank', 'rank',