commit
c59279e75e
5 changed files with 42 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
from models.User import User, user_schema
|
from models.User import User, user_schema, users_schema
|
||||||
|
|
||||||
class UserEndpoint(object):
|
class UserEndpoint(object):
|
||||||
def users():
|
def users():
|
||||||
user = User.query.first()
|
user = User.query.all()
|
||||||
response = user_schema.dumps(user)
|
response = users_schema.dumps(user)
|
||||||
return response
|
return response
|
||||||
|
|
4
app.py
4
app.py
|
@ -10,8 +10,8 @@ from flask_cors import CORS
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app, origins="http://localhost:3004")
|
||||||
|
app.config['CORS_HEADERS'] = 'Content-Type'
|
||||||
app.config.from_object(DevelopmentConfig)
|
app.config.from_object(DevelopmentConfig)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
ma.init_app(app)
|
ma.init_app(app)
|
||||||
|
|
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',
|
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),
|
||||||
|
|
|
@ -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,8 @@ class UserSchema(ma.ModelSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = (
|
fields = (
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'username',
|
||||||
|
'email',
|
||||||
'registered_on',
|
'registered_on',
|
||||||
'rank',
|
'rank',
|
||||||
'rank_certainty',
|
'rank_certainty',
|
||||||
|
|
Loading…
Reference in a new issue