fix: error on duplicate username/email registration (#1168)
* fix: error on duplicate username/email registration * Raise 409 http error on duplicate user registration * Add translation to conflict error messages * Update lang files * Remove key in translator parameter
This commit is contained in:
parent
633ec541ea
commit
67178f9b74
34 changed files with 106 additions and 33 deletions
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "Ce nom d'utilisateur est déjà pris",
|
||||
"email-conflict-error": "Cet email existe déjà"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "Ce nom d'utilisateur est déjà pris",
|
||||
"email-conflict-error": "Cet email existe déjà"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"exceptions": {
|
||||
"permission_denied": "You do not have permission to perform this action",
|
||||
"no-entry-found": "The requested resource was not found",
|
||||
"integrity-error": "Database integrity error"
|
||||
"integrity-error": "Database integrity error",
|
||||
"username-conflict-error": "This username is already taken",
|
||||
"email-conflict-error": "This email is already in use"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ from uuid import uuid4
|
|||
from fastapi import HTTPException, status
|
||||
|
||||
from mealie.core.security import hash_password
|
||||
from mealie.lang import local_provider
|
||||
from mealie.repos.repository_factory import AllRepositories
|
||||
from mealie.schema.group.group_preferences import CreateGroupPreferences
|
||||
from mealie.schema.user.registration import CreateUserRegistration
|
||||
|
@ -18,6 +19,7 @@ class RegistrationService:
|
|||
def __init__(self, logger: Logger, db: AllRepositories):
|
||||
self.logger = logger
|
||||
self.repos = db
|
||||
self.t = local_provider()
|
||||
|
||||
def _create_new_user(self, group: GroupInDB, new_group: bool) -> PrivateUser:
|
||||
new_user = UserIn(
|
||||
|
@ -54,6 +56,11 @@ class RegistrationService:
|
|||
def register_user(self, registration: CreateUserRegistration) -> PrivateUser:
|
||||
self.registration = registration
|
||||
|
||||
if self.repos.users.get_by_username(registration.username):
|
||||
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t.t("exceptions.username-conflict-error")})
|
||||
elif self.repos.users.get(registration.email, "email"):
|
||||
raise HTTPException(status.HTTP_409_CONFLICT, {"message": self.t.t("exceptions.email-conflict-error")})
|
||||
|
||||
self.logger.info(f"Registering user {registration.username}")
|
||||
token_entry = None
|
||||
new_group = False
|
||||
|
|
Loading…
Reference in a new issue