Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
🎨 Format with black, clean while lines, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Sep 8, 2018
1 parent 311209b commit ae853c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD={{cookiecutter.postgres_password}}
POSTGRES_DB=app
USERS_OPEN_REGISTRATION=False

Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,31 @@ def route_users_post(


@docs.register
@doc(
description='Create new user without the need to be logged in',
tags=['users'])
@app.route(f'{config.API_V1_STR}/users/open', methods=['POST'])
@use_kwargs({
'email': fields.Str(required=True),
'password': fields.Str(required=True),
'first_name': fields.Str(),
'last_name': fields.Str(),
'group_id': fields.Int(required=True),
})
@doc(description="Create new user without the need to be logged in", tags=["users"])
@app.route(f"{config.API_V1_STR}/users/open", methods=["POST"])
@use_kwargs(
{
"email": fields.Str(required=True),
"password": fields.Str(required=True),
"first_name": fields.Str(),
"last_name": fields.Str(),
"group_id": fields.Int(required=True),
}
)
@marshal_with(UserSchema())
def route_users_post_open(email=None,
password=None,
first_name=None,
last_name=None,
group_id=None):
def route_users_post_open(
email=None, password=None, first_name=None, last_name=None, group_id=None
):

if not config.USERS_OPEN_REGISTRATION:
abort(403, 'Open user resgistration is forbidden on this server')
abort(403, "Open user resgistration is forbidden on this server")

user = db_session.query(User).filter(User.email == email).first()

if user:
return abort(
400,
f'The user with this email already exists in the system: {email}')
400, f"The user with this email already exists in the system: {email}"
)

group = db_session.query(Group).filter(Group.id == group_id).first()

Expand All @@ -148,7 +146,8 @@ def route_users_post_open(email=None,
password=pwd_context.hash(password),
first_name=first_name,
last_name=last_name,
group=group)
group=group,
)

db_session.add(user)
db_session.commit()
Expand All @@ -157,11 +156,8 @@ def route_users_post_open(email=None,


@docs.register
@doc(
description='Get current user',
security=security_params,
tags=['users'])
@app.route(f'{config.API_V1_STR}/users/me', methods=['GET'])
@doc(description="Get current user", security=security_params, tags=["users"])
@app.route(f"{config.API_V1_STR}/users/me", methods=["GET"])
@marshal_with(UserSchema())
@jwt_required
def route_users_me_get():
Expand Down
8 changes: 4 additions & 4 deletions {{cookiecutter.project_slug}}/backend/app/app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os


def getenv_boolean(var_name, default_value=False):
result = default_value
env_value = os.getenv(var_name)
if not env_value is None:
result = env_value.upper() in ('TRUE', '1')
if env_value is not None:
result = env_value.upper() in ("TRUE", "1")
return result


API_V1_STR = "/api/v1"

SECRET_KEY = os.getenvb(b"SECRET_KEY")
Expand All @@ -30,5 +32,3 @@ def getenv_boolean(var_name, default_value=False):
FIRST_SUPERUSER_PASSWORD = os.getenv("FIRST_SUPERUSER_PASSWORD")

USERS_OPEN_REGISTRATION = getenv_boolean("USERS_OPEN_REGISTRATION")


1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ services:
- POSTGRES_DB=${POSTGRES_DB}
- FIRST_SUPERUSER={{cookiecutter.first_superuser}}
- FIRST_SUPERUSER_PASSWORD={{cookiecutter.first_superuser_password}}
- USERS_OPEN_REGISTRATION=${USERS_OPEN_REGISTRATION}
frontend:

0 comments on commit ae853c0

Please sign in to comment.