mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-03-01 07:25:39 +08:00
安全设置增加允许访问的国家地区、省份、是否局域网访问
This commit is contained in:
@@ -11,6 +11,8 @@ func init() {
|
||||
server.
|
||||
Prefix("/ui").
|
||||
Get("/download", new(DownloadAction)).
|
||||
GetPost("/selectProvincesPopup", new(SelectProvincesPopupAction)).
|
||||
GetPost("/selectCountriesPopup", new(SelectCountriesPopupAction)).
|
||||
|
||||
// 以下的需要压缩
|
||||
Helper(&actions.Gzip{Level: gzip.BestCompression}).
|
||||
|
||||
70
internal/web/actions/default/ui/selectCountriesPopup.go
Normal file
70
internal/web/actions/default/ui/selectCountriesPopup.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SelectCountriesPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SelectCountriesPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *SelectCountriesPopupAction) RunGet(params struct {
|
||||
CountryIds string
|
||||
}) {
|
||||
selectedCountryIds := utils.SplitNumbers(params.CountryIds)
|
||||
|
||||
countriesResp, err := this.RPC().RegionCountryRPC().FindAllEnabledRegionCountries(this.AdminContext(), &pb.FindAllEnabledRegionCountriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
countryMaps := []maps.Map{}
|
||||
for _, country := range countriesResp.Countries {
|
||||
countryMaps = append(countryMaps, maps.Map{
|
||||
"id": country.Id,
|
||||
"name": country.Name,
|
||||
"letter": strings.ToUpper(string(country.Pinyin[0][0])),
|
||||
"isChecked": lists.ContainsInt64(selectedCountryIds, country.Id),
|
||||
})
|
||||
}
|
||||
this.Data["countries"] = countryMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SelectCountriesPopupAction) RunPost(params struct {
|
||||
CountryIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
countryMaps := []maps.Map{}
|
||||
for _, countryId := range params.CountryIds {
|
||||
countryResp, err := this.RPC().RegionCountryRPC().FindEnabledRegionCountry(this.AdminContext(), &pb.FindEnabledRegionCountryRequest{CountryId: countryId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
country := countryResp.Country
|
||||
if country == nil {
|
||||
continue
|
||||
}
|
||||
countryMaps = append(countryMaps, maps.Map{
|
||||
"id": country.Id,
|
||||
"name": country.Name,
|
||||
})
|
||||
}
|
||||
this.Data["countries"] = countryMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
70
internal/web/actions/default/ui/selectProvincesPopup.go
Normal file
70
internal/web/actions/default/ui/selectProvincesPopup.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
const ChinaCountryId = 1
|
||||
|
||||
type SelectProvincesPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SelectProvincesPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *SelectProvincesPopupAction) RunGet(params struct {
|
||||
ProvinceIds string
|
||||
}) {
|
||||
selectedProvinceIds := utils.SplitNumbers(params.ProvinceIds)
|
||||
|
||||
provincesResp, err := this.RPC().RegionProvinceRPC().FindAllEnabledRegionProvincesWithCountryId(this.AdminContext(), &pb.FindAllEnabledRegionProvincesWithCountryIdRequest{CountryId: ChinaCountryId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
provinceMaps := []maps.Map{}
|
||||
for _, province := range provincesResp.Provinces {
|
||||
provinceMaps = append(provinceMaps, maps.Map{
|
||||
"id": province.Id,
|
||||
"name": province.Name,
|
||||
"isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id),
|
||||
})
|
||||
}
|
||||
this.Data["provinces"] = provinceMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SelectProvincesPopupAction) RunPost(params struct {
|
||||
ProvinceIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
provinceMaps := []maps.Map{}
|
||||
for _, provinceId := range params.ProvinceIds {
|
||||
provinceResp, err := this.RPC().RegionProvinceRPC().FindEnabledRegionProvince(this.AdminContext(), &pb.FindEnabledRegionProvinceRequest{ProvinceId: provinceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
province := provinceResp.Province
|
||||
if province == nil {
|
||||
continue
|
||||
}
|
||||
provinceMaps = append(provinceMaps, maps.Map{
|
||||
"id": province.Id,
|
||||
"name": province.Name,
|
||||
})
|
||||
}
|
||||
this.Data["provinces"] = provinceMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user