mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-09 00:20:26 +08:00
优化代码
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 生成Token
|
// Generate 生成Token
|
||||||
func Generate() string {
|
func Generate() string {
|
||||||
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
|
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func Generate() string {
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验Token
|
// Validate 校验Token
|
||||||
func Validate(token string) (b bool) {
|
func Validate(token string) (b bool) {
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -323,6 +323,10 @@ func (this *RPCClient) IPLibraryFileRPC() pb.IPLibraryFileServiceClient {
|
|||||||
return pb.NewIPLibraryFileServiceClient(this.pickConn())
|
return pb.NewIPLibraryFileServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) IPLibraryArtifactRPC() pb.IPLibraryArtifactServiceClient {
|
||||||
|
return pb.NewIPLibraryArtifactServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) IPListRPC() pb.IPListServiceClient {
|
func (this *RPCClient) IPListRPC() pb.IPListServiceClient {
|
||||||
return pb.NewIPListServiceClient(this.pickConn())
|
return pb.NewIPListServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["isUser"] = false
|
this.Data["isUser"] = false
|
||||||
this.Data["menu"] = "signIn"
|
this.Data["menu"] = "signIn"
|
||||||
|
|
||||||
timestamp := fmt.Sprintf("%d", time.Now().Unix())
|
var timestamp = fmt.Sprintf("%d", time.Now().Unix())
|
||||||
this.Data["token"] = stringutil.Md5(TokenSalt+timestamp) + timestamp
|
this.Data["token"] = stringutil.Md5(TokenSalt+timestamp) + timestamp
|
||||||
this.Data["from"] = params.From
|
this.Data["from"] = params.From
|
||||||
|
|
||||||
@@ -111,11 +111,11 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
if len(params.Token) <= 32 {
|
if len(params.Token) <= 32 {
|
||||||
this.Fail("请通过登录页面登录")
|
this.Fail("请通过登录页面登录")
|
||||||
}
|
}
|
||||||
timestampString := params.Token[32:]
|
var timestampString = params.Token[32:]
|
||||||
if stringutil.Md5(TokenSalt+timestampString) != params.Token[:32] {
|
if stringutil.Md5(TokenSalt+timestampString) != params.Token[:32] {
|
||||||
this.FailField("refresh", "登录页面已过期,请刷新后重试")
|
this.FailField("refresh", "登录页面已过期,请刷新后重试")
|
||||||
}
|
}
|
||||||
timestamp := types.Int64(timestampString)
|
var timestamp = types.Int64(timestampString)
|
||||||
if timestamp < time.Now().Unix()-1800 {
|
if timestamp < time.Now().Unix()-1800 {
|
||||||
this.FailField("refresh", "登录页面已过期,请刷新后重试")
|
this.FailField("refresh", "登录页面已过期,请刷新后重试")
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if otpLoginResp.Login != nil && otpLoginResp.Login.IsOn {
|
if otpLoginResp.Login != nil && otpLoginResp.Login.IsOn {
|
||||||
loginParams := maps.Map{}
|
var loginParams = maps.Map{}
|
||||||
err = json.Unmarshal(otpLoginResp.Login.ParamsJSON, &loginParams)
|
err = json.Unmarshal(otpLoginResp.Login.ParamsJSON, &loginParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -169,7 +169,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adminId := resp.AdminId
|
var adminId = resp.AdminId
|
||||||
params.Auth.StoreAdmin(adminId, params.Remember)
|
params.Auth.StoreAdmin(adminId, params.Remember)
|
||||||
|
|
||||||
// 记录日志
|
// 记录日志
|
||||||
|
|||||||
Reference in New Issue
Block a user