Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e734b4e

Browse files
♻️ Sign Up refactor (#12)
1 parent 1766c9c commit e734b4e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

‎.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ DOMAIN=localhost
55
# Environment: local, staging, production
66
ENVIRONMENT=local
77

8-
PROJECT_NAME="Full Stack FastAPI Project"
9-
STACK_NAME=full-stack-fastapi-project
8+
PROJECT_NAME="FastAPI Cloud"
9+
STACK_NAME=fastapi-cloud
1010

1111
# Backend
1212
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://localhost.tiangolo.com"
1313
SECRET_KEY=changethis
1414
FIRST_SUPERUSER=admin@example.com
1515
FIRST_SUPERUSER_PASSWORD=changethis
16-
USERS_OPEN_REGISTRATION=False
16+
USERS_OPEN_REGISTRATION=True
1717

1818
# Emails
1919
SMTP_HOST=

‎backend/app/api/routes/users.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
UpdatePassword,
1818
User,
1919
UserCreate,
20-
UserCreateOpen,
2120
UserOut,
21+
UserRegister,
2222
UsersOut,
2323
UserUpdate,
2424
UserUpdateMe,
@@ -122,8 +122,8 @@ def read_user_me(session: SessionDep, current_user: CurrentUser) -> Any:
122122
return current_user
123123

124124

125-
@router.post("/open", response_model=UserOut)
126-
def create_user_open(session: SessionDep, user_in: UserCreateOpen) -> Any:
125+
@router.post("/signup", response_model=UserOut)
126+
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
127127
"""
128128
Create new user without the need to be logged in.
129129
"""
@@ -138,7 +138,7 @@ def create_user_open(session: SessionDep, user_in: UserCreateOpen) -> Any:
138138
status_code=400,
139139
detail="The user with this email already exists in the system",
140140
)
141-
user_create = UserCreate.from_orm(user_in)
141+
user_create = UserCreate.model_validate(user_in)
142142
user = crud.create_user(session=session, user_create=user_create)
143143
return user
144144

‎backend/app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class UserCreate(UserBase):
3434

3535

3636
# TODO replace email str with EmailStr when sqlmodel supports it
37-
class UserCreateOpen(SQLModel):
37+
class UserRegister(SQLModel):
3838
email: str
3939
password: str
4040
full_name: str | None = None

‎backend/app/tests/api/routes/test_users.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ def test_update_password_me_same_password_error(
263263
)
264264

265265

266-
def test_create_user_open(client: TestClient) -> None:
266+
def test_register_user(client: TestClient) -> None:
267267
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
268268
username = random_email()
269269
password = random_lower_string()
270270
full_name = random_lower_string()
271271
data = {"email": username, "password": password, "full_name": full_name}
272272
r = client.post(
273-
f"{settings.API_V1_STR}/users/open",
273+
f"{settings.API_V1_STR}/users/signup",
274274
json=data,
275275
)
276276
assert r.status_code == 200
@@ -279,14 +279,14 @@ def test_create_user_open(client: TestClient) -> None:
279279
assert created_user["full_name"] == full_name
280280

281281

282-
def test_create_user_open_forbidden_error(client: TestClient) -> None:
282+
def test_register_user_forbidden_error(client: TestClient) -> None:
283283
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False):
284284
username = random_email()
285285
password = random_lower_string()
286286
full_name = random_lower_string()
287287
data = {"email": username, "password": password, "full_name": full_name}
288288
r = client.post(
289-
f"{settings.API_V1_STR}/users/open",
289+
f"{settings.API_V1_STR}/users/signup",
290290
json=data,
291291
)
292292
assert r.status_code == 403
@@ -295,7 +295,7 @@ def test_create_user_open_forbidden_error(client: TestClient) -> None:
295295
)
296296

297297

298-
def test_create_user_open_already_exists_error(client: TestClient) -> None:
298+
def test_register_user_already_exists_error(client: TestClient) -> None:
299299
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
300300
password = random_lower_string()
301301
full_name = random_lower_string()
@@ -305,7 +305,7 @@ def test_create_user_open_already_exists_error(client: TestClient) -> None:
305305
"full_name": full_name,
306306
}
307307
r = client.post(
308-
f"{settings.API_V1_STR}/users/open",
308+
f"{settings.API_V1_STR}/users/signup",
309309
json=data,
310310
)
311311
assert r.status_code == 400

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /