mirror of https://github.com/Xhofe/alist
feat(register-and-statistics): improve role handling logic
parent
94a7790d61
commit
7fe2f9a7eb
|
@ -2,6 +2,7 @@ package op
|
|||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
|
@ -82,6 +83,18 @@ var settingItemHooks = map[string]SettingItemHook{
|
|||
conf.SlicesMap[conf.IgnoreDirectLinkParams] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.DefaultRole: func(item *model.SettingItem) error {
|
||||
v := strings.TrimSpace(item.Value)
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
r, err := GetRoleByName(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
item.Value = strconv.Itoa(int(r.ID))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func RegisterSettingItemHook(key string, hook SettingItemHook) {
|
||||
|
|
|
@ -117,12 +117,7 @@ func Register(c *gin.Context) {
|
|||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
token, err := common.GenerateToken(user)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, gin.H{"token": token})
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
|
||||
type UserResp struct {
|
||||
|
|
Loading…
Reference in New Issue