add username
This commit is contained in:
parent
a2697b8a11
commit
257fd6a533
3 changed files with 36 additions and 6 deletions
30
migrations/versions/0e0f8ad1362d_.py
Normal file
30
migrations/versions/0e0f8ad1362d_.py
Normal 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 ###
|
|
@ -39,7 +39,7 @@ def upgrade():
|
|||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, 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('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),
|
||||
|
|
|
@ -49,6 +49,7 @@ class User(db.Model):
|
|||
__tablename__ = "users"
|
||||
|
||||
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)
|
||||
password = db.Column(db.String(255), nullable=False)
|
||||
registered_on = db.Column(db.DateTime, nullable=False)
|
||||
|
@ -57,14 +58,13 @@ class User(db.Model):
|
|||
elo = db.Column(db.Integer)
|
||||
rank_certainty = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
def __init__(self, email, password, admin=False,):
|
||||
print('user init')
|
||||
def __init__(self, username, email, password, rank='RU', admin=False):
|
||||
self.username = username
|
||||
self.email = email
|
||||
print('user email init')
|
||||
self.password = bcrypt.generate_password_hash(
|
||||
password, 13
|
||||
).decode()
|
||||
print('user password init')
|
||||
self.rank = rank
|
||||
self.registered_on = datetime.datetime.now()
|
||||
self.admin = admin
|
||||
|
||||
|
@ -106,7 +106,7 @@ class UserSchema(ma.ModelSchema):
|
|||
class Meta:
|
||||
fields = (
|
||||
'id',
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'registered_on',
|
||||
'rank',
|
||||
|
|
Loading…
Reference in a new issue