@@ -29,9 +29,13 @@ func getRoleOptions() string {
2929 return strings .Join (names , "," )
3030}
3131
32+ type SetTokenReq struct {
33+ Token string `json:"token" form:"token" binding:"required"`
34+ }
35+
3236func ResetToken (c * gin.Context ) {
3337 token := random .Token ()
34- item := model.SettingItem {Key : "token" , Value : token , Type : conf .TypeString , Group : model .SINGLE , Flag : model .PRIVATE }
38+ item := model.SettingItem {Key : conf . Token , Value : token , Type : conf .TypeString , Group : model .SINGLE , Flag : model .PRIVATE }
3539 if err := op .SaveSettingItem (& item ); err != nil {
3640 common .ErrorResp (c , err , 500 )
3741 return
@@ -40,6 +44,21 @@ func ResetToken(c *gin.Context) {
4044 common .SuccessResp (c , token )
4145}
4246
47+ func SetToken (c * gin.Context ) {
48+ var req SetTokenReq
49+ if err := c .ShouldBind (& req ); err != nil {
50+ common .ErrorResp (c , err , 400 )
51+ return
52+ }
53+ item := model.SettingItem {Key : conf .Token , Value : req .Token , Type : conf .TypeString , Group : model .SINGLE , Flag : model .PRIVATE }
54+ if err := op .SaveSettingItem (& item ); err != nil {
55+ common .ErrorResp (c , err , 500 )
56+ return
57+ }
58+ sign .Instance ()
59+ common .SuccessResp (c , req .Token )
60+ }
61+
4362func GetSetting (c * gin.Context ) {
4463 key := c .Query ("key" )
4564 keys := c .Query ("keys" )
0 commit comments