Skip to content

Commit 1f68668

Browse files
authored
🔥 Remove USERS_OPEN_REGISTRATION config, make registration enabled by default (#1274)
1 parent 7bba5a8 commit 1f68668

7 files changed

Lines changed: 31 additions & 71 deletions

File tree

‎.env‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,h
1313
SECRET_KEY=changethis
1414
FIRST_SUPERUSER=admin@example.com
1515
FIRST_SUPERUSER_PASSWORD=changethis
16-
USERS_OPEN_REGISTRATION=True
1716

1817
# Emails
1918
SMTP_HOST=

‎backend/README.md‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ Make sure your editor is using the correct Python virtual environment.
6363

6464
Modify or add SQLModel models for data and SQL tables in `./backend/app/models.py`, API endpoints in `./backend/app/api/`, CRUD (Create, Read, Update, Delete) utils in `./backend/app/crud.py`.
6565

66-
### Enabling Open User Registration
67-
68-
By default the backend has user registration disabled, but there's already a route to register users. If you want to allow users to register themselves, you can set the environment variable `USERS_OPEN_REGISTRATION` to `True` in the `.env` file.
69-
70-
After modifying the environment variables, restart the Docker containers to apply the changes. You can do this by running:
71-
72-
```console
73-
$ docker compose up -d
74-
```
75-
7666
### VS Code
7767

7868
There are already configurations in place to run the backend through the VS Code debugger, so that you can use breakpoints, pause and explore variables, etc.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ def register_user(session: SessionDep, user_in: UserRegister) -> Any:
146146
"""
147147
Create new user without the need to be logged in.
148148
"""
149-
if not settings.USERS_OPEN_REGISTRATION:
150-
raise HTTPException(
151-
status_code=403,
152-
detail="Open user registration is forbidden on this server",
153-
)
154149
user = crud.get_user_by_email(session=session, email=user_in.email)
155150
if user:
156151
raise HTTPException(

‎backend/app/core/config.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def emails_enabled(self) -> bool:
9494
# TODO: update type to EmailStr when sqlmodel supports it
9595
FIRST_SUPERUSER: str
9696
FIRST_SUPERUSER_PASSWORD: str
97-
USERS_OPEN_REGISTRATION: bool = False
9897

9998
def _check_default_secret(self, var_name: str, value: str | None) -> None:
10099
if value == "changethis":

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

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -283,62 +283,41 @@ def test_update_password_me_same_password_error(
283283

284284

285285
def test_register_user(client: TestClient, db: Session) -> None:
286-
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
287-
username = random_email()
288-
password = random_lower_string()
289-
full_name = random_lower_string()
290-
data = {"email": username, "password": password, "full_name": full_name}
291-
r = client.post(
292-
f"{settings.API_V1_STR}/users/signup",
293-
json=data,
294-
)
295-
assert r.status_code == 200
296-
created_user = r.json()
297-
assert created_user["email"] == username
298-
assert created_user["full_name"] == full_name
299-
300-
user_query = select(User).where(User.email == username)
301-
user_db = db.exec(user_query).first()
302-
assert user_db
303-
assert user_db.email == username
304-
assert user_db.full_name == full_name
305-
assert verify_password(password, user_db.hashed_password)
306-
286+
username = random_email()
287+
password = random_lower_string()
288+
full_name = random_lower_string()
289+
data = {"email": username, "password": password, "full_name": full_name}
290+
r = client.post(
291+
f"{settings.API_V1_STR}/users/signup",
292+
json=data,
293+
)
294+
assert r.status_code == 200
295+
created_user = r.json()
296+
assert created_user["email"] == username
297+
assert created_user["full_name"] == full_name
307298

308-
def test_register_user_forbidden_error(client: TestClient) -> None:
309-
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False):
310-
username = random_email()
311-
password = random_lower_string()
312-
full_name = random_lower_string()
313-
data = {"email": username, "password": password, "full_name": full_name}
314-
r = client.post(
315-
f"{settings.API_V1_STR}/users/signup",
316-
json=data,
317-
)
318-
assert r.status_code == 403
319-
assert (
320-
r.json()["detail"] == "Open user registration is forbidden on this server"
321-
)
299+
user_query = select(User).where(User.email == username)
300+
user_db = db.exec(user_query).first()
301+
assert user_db
302+
assert user_db.email == username
303+
assert user_db.full_name == full_name
304+
assert verify_password(password, user_db.hashed_password)
322305

323306

324307
def test_register_user_already_exists_error(client: TestClient) -> None:
325-
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
326-
password = random_lower_string()
327-
full_name = random_lower_string()
328-
data = {
329-
"email": settings.FIRST_SUPERUSER,
330-
"password": password,
331-
"full_name": full_name,
332-
}
333-
r = client.post(
334-
f"{settings.API_V1_STR}/users/signup",
335-
json=data,
336-
)
337-
assert r.status_code == 400
338-
assert (
339-
r.json()["detail"]
340-
== "The user with this email already exists in the system"
341-
)
308+
password = random_lower_string()
309+
full_name = random_lower_string()
310+
data = {
311+
"email": settings.FIRST_SUPERUSER,
312+
"password": password,
313+
"full_name": full_name,
314+
}
315+
r = client.post(
316+
f"{settings.API_V1_STR}/users/signup",
317+
json=data,
318+
)
319+
assert r.status_code == 400
320+
assert r.json()["detail"] == "The user with this email already exists in the system"
342321

343322

344323
def test_update_user(

‎deployment.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ You can set several variables, like:
133133
* `SECRET_KEY`: The secret key for the FastAPI project, used to sign tokens.
134134
* `FIRST_SUPERUSER`: The email of the first superuser, this superuser will be the one that can create new users.
135135
* `FIRST_SUPERUSER_PASSWORD`: The password of the first superuser.
136-
* `USERS_OPEN_REGISTRATION`: Whether to allow open registration of new users.
137136
* `SMTP_HOST`: The SMTP server host to send emails, this would come from your email provider (E.g. Mailgun, Sparkpost, Sendgrid, etc).
138137
* `SMTP_USER`: The SMTP server user to send emails.
139138
* `SMTP_PASSWORD`: The SMTP server password to send emails.

‎docker-compose.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ services:
5252
- SECRET_KEY=${SECRET_KEY?Variable not set}
5353
- FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set}
5454
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set}
55-
- USERS_OPEN_REGISTRATION=${USERS_OPEN_REGISTRATION}
5655
- SMTP_HOST=${SMTP_HOST}
5756
- SMTP_USER=${SMTP_USER}
5857
- SMTP_PASSWORD=${SMTP_PASSWORD}

0 commit comments

Comments
 (0)