77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
//go:build plus
|
|
|
|
package userconfigs
|
|
|
|
const (
|
|
MobileVerificationCodeLength = 6 // sms verification code length
|
|
MobileVerificationDailyLimit = 10 // sms verification times limit per day
|
|
)
|
|
|
|
// UserNotificationType 业务类型
|
|
type UserNotificationType = string
|
|
|
|
const (
|
|
UserNotificationTypeServer UserNotificationType = "server"
|
|
UserNotificationTypeBill UserNotificationType = "bill"
|
|
UserNotificationTypeNS UserNotificationType = "ns"
|
|
)
|
|
|
|
// UserNotificationMedia 媒介类型
|
|
type UserNotificationMedia = string
|
|
|
|
const (
|
|
UserNotificationMediaEmail UserNotificationMedia = "email"
|
|
)
|
|
|
|
// UserNotificationItem 单个业务配置
|
|
type UserNotificationItem struct {
|
|
Type UserNotificationType `json:"type"`
|
|
Medias []UserNotificationMedia `json:"medias"`
|
|
}
|
|
|
|
func FindAllUserNotificationItems() []*UserNotificationItem {
|
|
return []*UserNotificationItem{
|
|
{
|
|
Type: UserNotificationTypeServer,
|
|
Medias: []UserNotificationMedia{UserNotificationMediaEmail},
|
|
},
|
|
{
|
|
Type: UserNotificationTypeBill,
|
|
Medias: []UserNotificationMedia{UserNotificationMediaEmail},
|
|
},
|
|
{
|
|
Type: UserNotificationTypeNS,
|
|
Medias: []UserNotificationMedia{UserNotificationMediaEmail},
|
|
},
|
|
}
|
|
}
|
|
|
|
// UserNotificationConfig 用户通知订阅
|
|
type UserNotificationConfig struct {
|
|
Items []*UserNotificationItem `json:"items"`
|
|
}
|
|
|
|
func NewUserNotificationConfig() *UserNotificationConfig {
|
|
return &UserNotificationConfig{}
|
|
}
|
|
|
|
func (this *UserNotificationConfig) Support(notificationType UserNotificationType, media UserNotificationMedia) bool {
|
|
var items = this.Items
|
|
if len(items) == 0 {
|
|
items = FindAllUserNotificationItems()
|
|
}
|
|
|
|
for _, notification := range items {
|
|
if notification.Type == notificationType {
|
|
for _, allowMedia := range notification.Medias {
|
|
if allowMedia == media {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
return false
|
|
}
|