# HG changeset patch # User RhodeCode Admin # Date 2024-03-13 18:46:50 # Node ID 7a7f115938696c29a7c41c499a8faa3e0deceec5 # Parent 77661e7bceae655957fd0d0ddcdd374e30a7997a feat(forms): user profile form would detect nicely duplicates and show a form error. diff --git a/rhodecode/model/validation_schema/schemas/user_schema.py b/rhodecode/model/validation_schema/schemas/user_schema.py --- a/rhodecode/model/validation_schema/schemas/user_schema.py +++ b/rhodecode/model/validation_schema/schemas/user_schema.py @@ -64,6 +64,7 @@ class ChangePasswordSchema(colander.Sche @colander.deferred def deferred_username_validator(node, kw): + old_username = kw.get('username') def name_validator(node, value): msg = _( @@ -74,6 +75,11 @@ def deferred_username_validator(node, kw if not re.match(r'^[\w]{1}[\w\-\.]{0,254}$', value): raise colander.Invalid(node, msg) + if value != old_username: + existing_user = User.get_by_username(value, case_insensitive=True) + if existing_user: + raise colander.Invalid(node, 'Username is already taken') + return name_validator