fix(config)!: Token expire time (#145)
将配置中的过期时间单位统一为time.Duration,可以设置为`h`,`m`,`s`
This commit is contained in:
+1
-3
@@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @title 管理系统API
|
// @title 管理系统API
|
||||||
@@ -162,8 +161,7 @@ func InitGlobal() {
|
|||||||
|
|
||||||
//jwt
|
//jwt
|
||||||
//fmt.Println(global.Config.Jwt.PrivateKey)
|
//fmt.Println(global.Config.Jwt.PrivateKey)
|
||||||
global.Jwt = jwt.NewJwt(global.Config.Jwt.Key, global.Config.Jwt.ExpireDuration*time.Second)
|
global.Jwt = jwt.NewJwt(global.Config.Jwt.Key, global.Config.Jwt.ExpireDuration)
|
||||||
|
|
||||||
//locker
|
//locker
|
||||||
global.Lock = lock.NewLocal()
|
global.Lock = lock.NewLocal()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@ app:
|
|||||||
web-client: 1 # 1:启用 0:禁用
|
web-client: 1 # 1:启用 0:禁用
|
||||||
register: false #是否开启注册
|
register: false #是否开启注册
|
||||||
show-swagger: 0 # 1:启用 0:禁用
|
show-swagger: 0 # 1:启用 0:禁用
|
||||||
token-expire: 360000
|
token-expire: 168h
|
||||||
web-sso: true #web auth sso
|
web-sso: true #web auth sso
|
||||||
disable-pwd-login: false #禁用密码登录
|
disable-pwd-login: false #禁用密码登录
|
||||||
admin:
|
admin:
|
||||||
@@ -41,7 +41,7 @@ proxy:
|
|||||||
host: "http://127.0.0.1:1080"
|
host: "http://127.0.0.1:1080"
|
||||||
jwt:
|
jwt:
|
||||||
key: ""
|
key: ""
|
||||||
expire-duration: 360000
|
expire-duration: 168h
|
||||||
ldap:
|
ldap:
|
||||||
enable: false
|
enable: false
|
||||||
url: "ldap://ldap.example.com:389"
|
url: "ldap://ldap.example.com:389"
|
||||||
|
|||||||
+8
-7
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -13,12 +14,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
WebClient int `mapstructure:"web-client"`
|
WebClient int `mapstructure:"web-client"`
|
||||||
Register bool `mapstructure:"register"`
|
Register bool `mapstructure:"register"`
|
||||||
ShowSwagger int `mapstructure:"show-swagger"`
|
ShowSwagger int `mapstructure:"show-swagger"`
|
||||||
TokenExpire int `mapstructure:"token-expire"`
|
TokenExpire time.Duration `mapstructure:"token-expire"`
|
||||||
WebSso bool `mapstructure:"web-sso"`
|
WebSso bool `mapstructure:"web-sso"`
|
||||||
DisablePwdLogin bool `mapstructure:"disable-pwd-login"`
|
DisablePwdLogin bool `mapstructure:"disable-pwd-login"`
|
||||||
}
|
}
|
||||||
type Admin struct {
|
type Admin struct {
|
||||||
Title string `mapstructure:"title"`
|
Title string `mapstructure:"title"`
|
||||||
@@ -73,7 +74,7 @@ func Init(rowVal *Config, path string) *viper.Viper {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
if err := v.Unmarshal(rowVal); err != nil {
|
if err := v.Unmarshal(rowVal); err != nil {
|
||||||
fmt.Println(err)
|
panic(fmt.Errorf("Fatal error config: %s \n", err))
|
||||||
}
|
}
|
||||||
rowVal.Rustdesk.LoadKeyFile()
|
rowVal.Rustdesk.LoadKeyFile()
|
||||||
rowVal.Rustdesk.ParsePort()
|
rowVal.Rustdesk.ParsePort()
|
||||||
|
|||||||
+3
-2
@@ -476,9 +476,10 @@ func (us *UserService) getAdminUserCount() int64 {
|
|||||||
func (us *UserService) UserTokenExpireTimestamp() int64 {
|
func (us *UserService) UserTokenExpireTimestamp() int64 {
|
||||||
exp := global.Config.App.TokenExpire
|
exp := global.Config.App.TokenExpire
|
||||||
if exp == 0 {
|
if exp == 0 {
|
||||||
exp = 3600 * 24 * 7
|
//默认七天
|
||||||
|
exp = 604800
|
||||||
}
|
}
|
||||||
return time.Now().Add(time.Second * time.Duration(exp)).Unix()
|
return time.Now().Add(exp).Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *UserService) RefreshAccessToken(ut *model.UserToken) {
|
func (us *UserService) RefreshAccessToken(ut *model.UserToken) {
|
||||||
|
|||||||
Reference in New Issue
Block a user