mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 15:20:25 +08:00
增加商业版激活功能
This commit is contained in:
52
internal/web/actions/default/settings/authority/activate.go
Normal file
52
internal/web/actions/default/settings/authority/activate.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -26,24 +27,28 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
var keyMap maps.Map = nil
|
var keyMap maps.Map = nil
|
||||||
teaconst.IsPlus = false
|
teaconst.IsPlus = false
|
||||||
if keyResp.AuthorityKey != nil {
|
var key = keyResp.AuthorityKey
|
||||||
if len(keyResp.AuthorityKey.MacAddresses) == 0 {
|
if key != nil {
|
||||||
keyResp.AuthorityKey.MacAddresses = []string{}
|
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 {
|
if isActive {
|
||||||
teaconst.IsPlus = true
|
teaconst.IsPlus = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isExpiring := isActive && key.DayTo < timeutil.Format("Y-m-d", time.Now().AddDate(0, 0, 7))
|
||||||
|
|
||||||
keyMap = maps.Map{
|
keyMap = maps.Map{
|
||||||
"dayFrom": keyResp.AuthorityKey.DayFrom,
|
"dayFrom": key.DayFrom,
|
||||||
"dayTo": keyResp.AuthorityKey.DayTo,
|
"dayTo": key.DayTo,
|
||||||
"macAddresses": keyResp.AuthorityKey.MacAddresses,
|
"macAddresses": key.MacAddresses,
|
||||||
"hostname": keyResp.AuthorityKey.Hostname,
|
"hostname": key.Hostname,
|
||||||
"company": keyResp.AuthorityKey.Company,
|
"company": key.Company,
|
||||||
"nodes": keyResp.AuthorityKey.Nodes,
|
"nodes": key.Nodes,
|
||||||
"isExpired": !isActive,
|
"isExpired": !isActive,
|
||||||
|
"isExpiring": isExpiring,
|
||||||
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt),
|
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ func init() {
|
|||||||
Helper(settingutils.NewAdvancedHelper("authority")).
|
Helper(settingutils.NewAdvancedHelper("authority")).
|
||||||
Prefix("/settings/authority").
|
Prefix("/settings/authority").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
|
GetPost("/activate", new(ActivateAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
|
|||||||
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
|
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
|
||||||
}
|
}
|
||||||
if teaconst.BuildPlus {
|
if teaconst.BuildPlus {
|
||||||
tabbar.Add("企业版认证", "", "/settings/authority", "", this.tab == "authority")
|
tabbar.Add("商业版认证", "", "/settings/authority", "", this.tab == "authority")
|
||||||
}
|
}
|
||||||
|
|
||||||
//tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
|
//tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<first-menu>
|
<first-menu>
|
||||||
<menu-item href="/settings/authority" code="index">认证信息</menu-item>
|
<menu-item href="/settings/authority" code="index">认证信息</menu-item>
|
||||||
<menu-item href="/settings/authority/nodes" code="node">认证节点</menu-item>
|
<!--<menu-item href="/settings/authority/nodes" code="node">认证节点</menu-item>-->
|
||||||
|
<menu-item href="/settings/authority/activate" code="activate">激活</menu-item>
|
||||||
</first-menu>
|
</first-menu>
|
||||||
18
web/views/@default/settings/authority/activate.html
Normal file
18
web/views/@default/settings/authority/activate.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "menu"}
|
||||||
|
|
||||||
|
<div class="margin"></div>
|
||||||
|
|
||||||
|
<form class="ui form" data-tea-action="$" data-tea-success="success" spellcheck="false">
|
||||||
|
<csrf-token></csrf-token>
|
||||||
|
<table class="ui table definition selectable">
|
||||||
|
<tr>
|
||||||
|
<td class="title">激活码 *</td>
|
||||||
|
<td>
|
||||||
|
<textarea rows="4" name="key" ref="focus"></textarea>
|
||||||
|
<p class="comment">请输入商业版激活码。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<submit-btn>激活</submit-btn>
|
||||||
|
</form>
|
||||||
3
web/views/@default/settings/authority/activate.js
Normal file
3
web/views/@default/settings/authority/activate.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifySuccess("激活成功", "/settings/authority")
|
||||||
|
})
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<div v-if="key != null">
|
<div v-if="key != null">
|
||||||
<div class="margin"></div>
|
<div class="margin"></div>
|
||||||
|
|
||||||
<div class="ui message green icon">
|
<div class="ui message green icon" v-if="!key.isExpired">
|
||||||
<i class="icon gem outline small yellow"></i>
|
<i class="icon gem outline small yellow"></i>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
恭喜您已经成为尊贵的商业版用户。
|
恭喜您已经成为尊贵的商业版用户。
|
||||||
@@ -18,7 +18,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="title">状态</td>
|
<td class="title">状态</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="green">已认证</span>
|
<span class="red" v-if="key.isExpiring">即将过期</span>
|
||||||
|
<span class="red" v-else-if="key.isExpired">已过期</span>
|
||||||
|
<span class="green" v-else>已认证</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="key.nodes > 0">
|
<tr v-if="key.nodes > 0">
|
||||||
@@ -36,7 +38,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="title">结束日期</td>
|
<td class="title">结束日期</td>
|
||||||
<td>{{key.dayTo}}
|
<td>{{key.dayTo}}
|
||||||
<div v-if="key.isExpired" style="margin-top: 0.5em">
|
<div v-if="key.isExpiring" style="margin-top: 0.5em">
|
||||||
|
<span class="red">即将过期</span>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="key.isExpired" style="margin-top: 0.5em">
|
||||||
<span class="red">已过期,请尽快更新认证信息。</span>
|
<span class="red">已过期,请尽快更新认证信息。</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user