fix next uid

Signed-off-by: wozulong <>
This commit is contained in:
wozulong 2024-03-21 15:02:47 +08:00
parent 9855343aa8
commit 0907fa6994
7 changed files with 69 additions and 17 deletions

View File

@ -516,7 +516,7 @@ func UpdateSelf(c *gin.Context) {
return return
} }
func DeleteUser(c *gin.Context) { func HardDeleteUser(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id")) id, err := strconv.Atoi(c.Param("id"))
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
@ -525,7 +525,7 @@ func DeleteUser(c *gin.Context) {
}) })
return return
} }
originUser, err := model.GetUserById(id, false) originUser, err := model.GetUserByIdUnscoped(id, false)
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": false, "success": false,
@ -549,6 +549,12 @@ func DeleteUser(c *gin.Context) {
}) })
return return
} }
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
})
return
} }
func DeleteSelf(c *gin.Context) { func DeleteSelf(c *gin.Context) {

View File

@ -65,7 +65,7 @@ func CheckUserExistOrDeleted(username string, email string) (bool, error) {
func GetMaxUserId() int { func GetMaxUserId() int {
var user User var user User
DB.Last(&user) DB.Unscoped().Last(&user)
return user.Id return user.Id
} }
@ -93,6 +93,20 @@ func GetUserById(id int, selectAll bool) (*User, error) {
return &user, err return &user, err
} }
func GetUserByIdUnscoped(id int, selectAll bool) (*User, error) {
if id == 0 {
return nil, errors.New("id 为空!")
}
user := User{Id: id}
var err error = nil
if selectAll {
err = DB.Unscoped().First(&user, "id = ?", id).Error
} else {
err = DB.Unscoped().Omit("password").First(&user, "id = ?", id).Error
}
return &user, err
}
func GetUserIdByAffCode(affCode string) (int, error) { func GetUserIdByAffCode(affCode string) (int, error) {
if affCode == "" { if affCode == "" {
return 0, errors.New("affCode 为空!") return 0, errors.New("affCode 为空!")

View File

@ -63,7 +63,7 @@ func SetApiRouter(router *gin.Engine) {
adminRoute.POST("/", controller.CreateUser) adminRoute.POST("/", controller.CreateUser)
adminRoute.POST("/manage", controller.ManageUser) adminRoute.POST("/manage", controller.ManageUser)
adminRoute.PUT("/", controller.UpdateUser) adminRoute.PUT("/", controller.UpdateUser)
adminRoute.DELETE("/:id", controller.DeleteUser) adminRoute.DELETE("/:id", controller.HardDeleteUser)
} }
} }
optionRoute := apiRouter.Group("/option") optionRoute := apiRouter.Group("/option")

View File

@ -18,6 +18,8 @@ const GitHubOAuth = () => {
const res = await API.get(`/api/oauth/github?code=${code}&state=${state}&aff=${aff}`); const res = await API.get(`/api/oauth/github?code=${code}&state=${state}&aff=${aff}`);
const { success, message, data } = res.data; const { success, message, data } = res.data;
if (success) { if (success) {
localStorage.removeItem('aff');
if (message === 'bind') { if (message === 'bind') {
showSuccess('绑定成功!'); showSuccess('绑定成功!');
navigate('/setting'); navigate('/setting');

View File

@ -18,6 +18,8 @@ const LinuxDoOAuth = () => {
const res = await API.get(`/api/oauth/linuxdo?code=${code}&state=${state}&aff=${aff}`); const res = await API.get(`/api/oauth/linuxdo?code=${code}&state=${state}&aff=${aff}`);
const { success, message, data } = res.data; const { success, message, data } = res.data;
if (success) { if (success) {
localStorage.removeItem('aff');
if (message === 'bind') { if (message === 'bind') {
showSuccess('绑定成功!'); showSuccess('绑定成功!');
navigate('/setting'); navigate('/setting');

View File

@ -69,6 +69,8 @@ const RegisterForm = () => {
); );
const { success, message } = res.data; const { success, message } = res.data;
if (success) { if (success) {
localStorage.removeItem('aff');
navigate('/login'); navigate('/login');
showSuccess('注册成功!'); showSuccess('注册成功!');
} else { } else {

View File

@ -112,19 +112,33 @@ const UsersTable = () => {
</> </>
} }
<Popconfirm {
title="确定是否要删除此用户?" record.DeletedAt !== null ? <Popconfirm
content="硬删除,此修改将不可逆" title="确定是否要删除此用户?"
okType={'danger'} content="硬删除,此修改将不可逆"
position={'left'} okType={'danger'}
onConfirm={() => { position={'left'}
manageUser(record.username, 'delete', record).then(() => { onConfirm={() => {
removeRecord(record.id); hardDeleteUser(record.id).then(() => {
}); removeRecord(record.id);
}} });
> }}
<Button theme="light" type="danger" style={{ marginRight: 1 }}>删除</Button> >
</Popconfirm> <Button theme="light" type="danger" style={{ marginRight: 1 }}>永久删除</Button>
</Popconfirm> : <Popconfirm
title="确定是否要删除此用户?"
content="软删除,数据依然留底"
okType={'danger'}
position={'left'}
onConfirm={() => {
manageUser(record.username, 'delete', record).then(() => {
record.DeletedAt = new Date();
});
}}
>
<Button theme="light" type="danger" style={{ marginRight: 1 }}>删除</Button>
</Popconfirm>
}
</div>) </div>)
}]; }];
@ -216,9 +230,21 @@ const UsersTable = () => {
setUsers(newUsers); setUsers(newUsers);
} else { } else {
showError(message); showError(message);
throw new Error(message);
} }
}; };
const hardDeleteUser = async (userId) => {
const res = await API.delete('/api/user/' + userId);
const { success, message } = res.data;
if (success) {
showSuccess('操作成功完成!');
} else {
showError(message);
throw new Error(message);
}
}
const renderStatus = (status) => { const renderStatus = (status) => {
switch (status) { switch (status) {
case 1: case 1: