From 35fd437aaadef6fb1ce7b185b65942cd8969bf2f Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 16 Sep 2021 10:32:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E4=B8=9A=E7=89=88?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/settings/authority/activate.go | 52 +++++++++++++++++++ .../default/settings/authority/index.go | 25 +++++---- .../default/settings/authority/init.go | 1 + .../settings/settingutils/advanced_helper.go | 2 +- .../@default/settings/authority/@menu.html | 3 +- .../@default/settings/authority/activate.html | 18 +++++++ .../@default/settings/authority/activate.js | 3 ++ .../@default/settings/authority/index.html | 11 ++-- 8 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 internal/web/actions/default/settings/authority/activate.go create mode 100644 web/views/@default/settings/authority/activate.html create mode 100644 web/views/@default/settings/authority/activate.js diff --git a/internal/web/actions/default/settings/authority/activate.go b/internal/web/actions/default/settings/authority/activate.go new file mode 100644 index 00000000..388e216a --- /dev/null +++ b/internal/web/actions/default/settings/authority/activate.go @@ -0,0 +1,52 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package server + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type ActivateAction struct { + actionutils.ParentAction +} + +func (this *ActivateAction) Init() { + this.Nav("", "", "activate") +} + +func (this *ActivateAction) RunGet(params struct{}) { + this.Show() +} + +func (this *ActivateAction) RunPost(params struct { + Key string + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + if len(params.Key) == 0 { + this.FailField("key", "请输入激活码") + } + + resp, err := this.RPC().AuthorityKeyRPC().ValidateAuthorityKey(this.AdminContext(), &pb.ValidateAuthorityKeyRequest{Key: params.Key}) + if err != nil { + this.ErrorPage(err) + return + } + + if resp.IsOk { + _, err := this.RPC().AuthorityKeyRPC().UpdateAuthorityKey(this.AdminContext(), &pb.UpdateAuthorityKeyRequest{ + Value: params.Key, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() + } else { + this.FailField("key", "无法激活:"+resp.Error) + } +} diff --git a/internal/web/actions/default/settings/authority/index.go b/internal/web/actions/default/settings/authority/index.go index 9feef0f8..0a552c17 100644 --- a/internal/web/actions/default/settings/authority/index.go +++ b/internal/web/actions/default/settings/authority/index.go @@ -8,6 +8,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" timeutil "github.com/iwind/TeaGo/utils/time" + "time" ) type IndexAction struct { @@ -26,24 +27,28 @@ func (this *IndexAction) RunGet(params struct{}) { } var keyMap maps.Map = nil teaconst.IsPlus = false - if keyResp.AuthorityKey != nil { - if len(keyResp.AuthorityKey.MacAddresses) == 0 { - keyResp.AuthorityKey.MacAddresses = []string{} + var key = keyResp.AuthorityKey + if key != nil { + if len(key.MacAddresses) == 0 { + key.MacAddresses = []string{} } - isActive := len(keyResp.AuthorityKey.DayTo) > 0 && keyResp.AuthorityKey.DayTo >= timeutil.Format("Y-m-d") + isActive := len(key.DayTo) > 0 && key.DayTo >= timeutil.Format("Y-m-d") if isActive { teaconst.IsPlus = true } + isExpiring := isActive && key.DayTo < timeutil.Format("Y-m-d", time.Now().AddDate(0, 0, 7)) + keyMap = maps.Map{ - "dayFrom": keyResp.AuthorityKey.DayFrom, - "dayTo": keyResp.AuthorityKey.DayTo, - "macAddresses": keyResp.AuthorityKey.MacAddresses, - "hostname": keyResp.AuthorityKey.Hostname, - "company": keyResp.AuthorityKey.Company, - "nodes": keyResp.AuthorityKey.Nodes, + "dayFrom": key.DayFrom, + "dayTo": key.DayTo, + "macAddresses": key.MacAddresses, + "hostname": key.Hostname, + "company": key.Company, + "nodes": key.Nodes, "isExpired": !isActive, + "isExpiring": isExpiring, "updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt), } } diff --git a/internal/web/actions/default/settings/authority/init.go b/internal/web/actions/default/settings/authority/init.go index 77e2f586..abc2af60 100644 --- a/internal/web/actions/default/settings/authority/init.go +++ b/internal/web/actions/default/settings/authority/init.go @@ -14,6 +14,7 @@ func init() { Helper(settingutils.NewAdvancedHelper("authority")). Prefix("/settings/authority"). Get("", new(IndexAction)). + GetPost("/activate", new(ActivateAction)). EndAll() }) } diff --git a/internal/web/actions/default/settings/settingutils/advanced_helper.go b/internal/web/actions/default/settings/settingutils/advanced_helper.go index 1ee2b042..65500b7c 100644 --- a/internal/web/actions/default/settings/settingutils/advanced_helper.go +++ b/internal/web/actions/default/settings/settingutils/advanced_helper.go @@ -39,7 +39,7 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes") } if teaconst.BuildPlus { - tabbar.Add("企业版认证", "", "/settings/authority", "", this.tab == "authority") + tabbar.Add("商业版认证", "", "/settings/authority", "", this.tab == "authority") } //tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup") diff --git a/web/views/@default/settings/authority/@menu.html b/web/views/@default/settings/authority/@menu.html index 43beab87..8849dc7e 100644 --- a/web/views/@default/settings/authority/@menu.html +++ b/web/views/@default/settings/authority/@menu.html @@ -1,4 +1,5 @@ 认证信息 - 认证节点 + + 激活 \ No newline at end of file diff --git a/web/views/@default/settings/authority/activate.html b/web/views/@default/settings/authority/activate.html new file mode 100644 index 00000000..7eebe4e1 --- /dev/null +++ b/web/views/@default/settings/authority/activate.html @@ -0,0 +1,18 @@ +{$layout} +{$template "menu"} + +
+ +
+ + + + + + +
激活码 * + +

请输入商业版激活码。

+
+ 激活 +
\ No newline at end of file diff --git a/web/views/@default/settings/authority/activate.js b/web/views/@default/settings/authority/activate.js new file mode 100644 index 00000000..46a2cea1 --- /dev/null +++ b/web/views/@default/settings/authority/activate.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifySuccess("激活成功", "/settings/authority") +}) \ No newline at end of file diff --git a/web/views/@default/settings/authority/index.html b/web/views/@default/settings/authority/index.html index ffa442ef..36799be3 100644 --- a/web/views/@default/settings/authority/index.html +++ b/web/views/@default/settings/authority/index.html @@ -6,7 +6,7 @@
-
+
恭喜您已经成为尊贵的商业版用户。 @@ -18,7 +18,9 @@ 状态 - 已认证 + 即将过期 + 已过期 + 已认证 @@ -36,7 +38,10 @@ 结束日期 {{key.dayTo}} -
+
+ 即将过期 +
+
已过期,请尽快更新认证信息。