|
@@ -351,11 +351,9 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
user = Users.get_user_by_email(email)
|
|
|
if not user:
|
|
|
try:
|
|
|
- user_count = Users.get_num_users()
|
|
|
-
|
|
|
role = (
|
|
|
"admin"
|
|
|
- if user_count == 0
|
|
|
+ if not Users.has_users()
|
|
|
else request.app.state.config.DEFAULT_USER_ROLE
|
|
|
)
|
|
|
|
|
@@ -489,7 +487,7 @@ async def signin(request: Request, response: Response, form_data: SigninForm):
|
|
|
if Users.get_user_by_email(admin_email.lower()):
|
|
|
user = Auths.authenticate_user(admin_email.lower(), admin_password)
|
|
|
else:
|
|
|
- if Users.get_num_users() != 0:
|
|
|
+ if Users.has_users():
|
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.EXISTING_USERS)
|
|
|
|
|
|
await signup(
|
|
@@ -556,6 +554,7 @@ async def signin(request: Request, response: Response, form_data: SigninForm):
|
|
|
|
|
|
@router.post("/signup", response_model=SessionUserResponse)
|
|
|
async def signup(request: Request, response: Response, form_data: SignupForm):
|
|
|
+ has_users = Users.has_users()
|
|
|
|
|
|
if WEBUI_AUTH:
|
|
|
if (
|
|
@@ -566,12 +565,11 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
|
|
|
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED
|
|
|
)
|
|
|
else:
|
|
|
- if Users.get_num_users() != 0:
|
|
|
+ if has_users:
|
|
|
raise HTTPException(
|
|
|
status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED
|
|
|
)
|
|
|
|
|
|
- user_count = Users.get_num_users()
|
|
|
if not validate_email_format(form_data.email.lower()):
|
|
|
raise HTTPException(
|
|
|
status.HTTP_400_BAD_REQUEST, detail=ERROR_MESSAGES.INVALID_EMAIL_FORMAT
|
|
@@ -581,9 +579,7 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
|
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
|
|
|
|
|
|
try:
|
|
|
- role = (
|
|
|
- "admin" if user_count == 0 else request.app.state.config.DEFAULT_USER_ROLE
|
|
|
- )
|
|
|
+ role = "admin" if not has_users else request.app.state.config.DEFAULT_USER_ROLE
|
|
|
|
|
|
# The password passed to bcrypt must be 72 bytes or fewer. If it is longer, it will be truncated before hashing.
|
|
|
if len(form_data.password.encode("utf-8")) > 72:
|
|
@@ -644,7 +640,7 @@ async def signup(request: Request, response: Response, form_data: SignupForm):
|
|
|
user.id, request.app.state.config.USER_PERMISSIONS
|
|
|
)
|
|
|
|
|
|
- if user_count == 0:
|
|
|
+ if not has_users:
|
|
|
# Disable signup after the first user is created
|
|
|
request.app.state.config.ENABLE_SIGNUP = False
|
|
|
|