From 5ae57435badc652439998a8bca75beef17582192 Mon Sep 17 00:00:00 2001 From: MartialBE Date: Wed, 15 May 2024 12:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20chore:=20prohibit=20users=20from?= =?UTF-8?q?=20modifying=20usernames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/user.go | 4 ++-- model/user.go | 3 --- web/src/views/Profile/index.js | 5 +++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/controller/user.go b/controller/user.go index 7f69998f..95cb4dee 100644 --- a/controller/user.go +++ b/controller/user.go @@ -415,8 +415,8 @@ func UpdateSelf(c *gin.Context) { } cleanUser := model.User{ - Id: c.GetInt("id"), - Username: user.Username, + Id: c.GetInt("id"), + // Username: user.Username, Password: user.Password, DisplayName: user.DisplayName, } diff --git a/model/user.go b/model/user.go index d339e61f..27933038 100644 --- a/model/user.go +++ b/model/user.go @@ -139,9 +139,6 @@ func (user *User) Insert(inviterId int) error { } func (user *User) Update(updatePassword bool) error { - if RecordExists(&User{}, "username", user.Username, user.Id) { - return errors.New("用户名已存在!") - } var err error if updatePassword { user.Password, err = common.Password2Hash(user.Password) diff --git a/web/src/views/Profile/index.js b/web/src/views/Profile/index.js index 25daff9e..67ba628f 100644 --- a/web/src/views/Profile/index.js +++ b/web/src/views/Profile/index.js @@ -107,7 +107,7 @@ export default function Profile() { const submit = async () => { try { let inputValue = inputs; - inputValue.username = trims(inputValue.username); + // inputValue.username = trims(inputValue.username); inputValue.display_name = trims(inputValue.display_name); await validationSchema.validate(inputValue); const res = await API.put(`/api/user/self`, inputValue); @@ -170,7 +170,8 @@ export default function Profile() { label="用户名" type="text" value={inputs.username || ''} - onChange={handleInputChange} + // onChange={handleInputChange} + disabled name="username" placeholder="请输入用户名" />