2021-01-20 12:07:40 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2021-01-20 12:07:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateTheme validates and update Theme configuration.
|
|
|
|
func ValidateTheme(configuration *schema.Configuration, validator *schema.StructValidator) {
|
2021-06-01 04:09:50 +00:00
|
|
|
if configuration.Theme == "" {
|
|
|
|
configuration.Theme = "light"
|
|
|
|
}
|
|
|
|
|
2021-06-17 06:42:03 +00:00
|
|
|
validThemes := regexp.MustCompile("light|dark|grey|auto")
|
|
|
|
|
2021-01-20 12:07:40 +00:00
|
|
|
if !validThemes.MatchString(configuration.Theme) {
|
2021-06-17 06:42:03 +00:00
|
|
|
validator.Push(fmt.Errorf("Theme: %s is not valid, valid themes are: \"light\", \"dark\", \"grey\" or \"auto\"", configuration.Theme))
|
2021-01-20 12:07:40 +00:00
|
|
|
}
|
|
|
|
}
|