Check if username exists

This commit is contained in:
amcmanu3 2022-07-05 19:49:51 -04:00
parent 964b3bc4c3
commit a498ef8986
4 changed files with 23 additions and 4 deletions

View File

@ -100,6 +100,10 @@ class UsersController:
def get_all_user_ids() -> t.List[int]:
return HelperUsers.get_all_user_ids()
@staticmethod
def get_all_usernames():
return HelperUsers.get_all_usernames()
@staticmethod
def get_id_by_name(username):
return HelperUsers.get_user_id_by_name(username)

View File

@ -99,6 +99,14 @@ class HelperUsers:
query = Users.select().where(Users.username != "system")
return query
@staticmethod
def get_all_usernames():
usernames = []
query = Users.select().where(Users.username != "system")
for user in query:
usernames.append(user.username)
return usernames
@staticmethod
def get_all_user_ids() -> t.List[int]:
return [

View File

@ -1860,6 +1860,13 @@ class PanelHandler(BaseHandler):
)
user_id = bleach.clean(self.get_argument("id", None))
username = bleach.clean(self.get_argument("username", None).lower())
if (
username != self.controller.users.get_user_by_id(user_id)["username"]
and username in self.controller.users.get_all_usernames()
):
self.redirect(
"/panel/error?error=Duplicate User: Useranme already exists."
)
password0 = bleach.clean(self.get_argument("password0", None))
password1 = bleach.clean(self.get_argument("password1", None))
email = bleach.clean(self.get_argument("email", "default@example.com"))

View File

@ -76,28 +76,28 @@
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'userNameDesc', data['lang'])
}}</small> </label>
<input type="text" class="form-control" name="username" id="username" autocomplete="off"
value="{{ data['user']['username'] }}" placeholder="User Name">
data-lpignore="true" value="{{ data['user']['username'] }}" placeholder="User Name">
</div>
<div class="form-group">
<label class="form-label" for="password0">{{ translate('userConfig', 'password', data['lang'])
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'leaveBlank', data['lang']) }}
</small> </label>
<input type="password" class="form-control" name="password0" id="password0" value=""
autocomplete="off" placeholder="Password">
autocomplete="new-password" data-lpignore="true" placeholder="Password">
</div>
<div class="form-group">
<label class="form-label" for="password1">{{ translate('userConfig', 'repeat', data['lang']) }}
<small class="text-muted ml-1"> - {{ translate('userConfig', 'leaveBlank', data['lang'])
}}</small> </label>
<input type="password" class="form-control" name="password1" id="password1" value=""
autocomplete="off" placeholder="Repeat Password">
autocomplete="new-password" data-lpignore="true" placeholder="Repeat Password">
</div>
<div class="form-group">
<label class="form-label" for="email">{{ translate('userConfig', 'gravEmail', data['lang'])
}}<small class="text-muted ml-1"> - {{ translate('userConfig', 'gravDesc', data['lang'])
}}</small> </label>
<input type="email" class="form-control" name="email" id="email" autocomplete="off"
value="{{ data['user']['email'] }}" placeholder="Gravatar Email">
data-lpignore="true" value="{{ data['user']['email'] }}" placeholder="Gravatar Email">
</div>
<div class="form-group">
<label class="form-label" for="language">{{ translate('userConfig', 'userLang', data['lang'])