All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 7m38s
40 lines
955 B
Go
40 lines
955 B
Go
package auth
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/perfect-panel/server/internal/config"
|
|
)
|
|
|
|
// IsEmailDomainWhitelisted checks if the email's domain is in the comma-separated whitelist.
|
|
// Returns false if the email format is invalid.
|
|
func IsEmailDomainWhitelisted(email, whitelistCSV string) bool {
|
|
if whitelistCSV == "" {
|
|
return false
|
|
}
|
|
parts := strings.SplitN(email, "@", 2)
|
|
if len(parts) != 2 {
|
|
return false
|
|
}
|
|
domain := strings.ToLower(strings.TrimSpace(parts[1]))
|
|
for _, d := range strings.Split(whitelistCSV, ",") {
|
|
if strings.ToLower(strings.TrimSpace(d)) == domain {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func ShouldGrantTrialForEmail(register config.RegisterConfig, email string) bool {
|
|
if !register.EnableTrial {
|
|
return false
|
|
}
|
|
if !register.EnableTrialEmailWhitelist {
|
|
return true
|
|
}
|
|
if register.TrialEmailDomainWhitelist == "" {
|
|
return false
|
|
}
|
|
return IsEmailDomainWhitelisted(email, register.TrialEmailDomainWhitelist)
|
|
}
|