func (f *Factory) AddBuiltinTemplates() error {
	for name := range PageTemplates {
		if err := f.AddBuiltinTemplate(name); err != nil {
			return fmt.Errorf("Failed to load built-in template %s: %s", name, err)
		}
	}
	return nil
}
AddBuiltinTemplates adds all built-in template to Factory
package ui
import (
	"bytes"
	"fmt"
	"github.com/greenpau/caddy-authorize/pkg/utils/cfgutils"
	"io/ioutil"
	"path"
	"strings"
	"text/template"
)
var Themes = map[string]interface{}{
	"basic": true,
}
type Factory struct {
	Templates               map[string]*Template `json:"templates,omitempty"`
	Title                   string               `json:"title,omitempty"`
	LogoURL                 string               `json:"logo_url,omitempty"`
	LogoDescription         string               `json:"logo_description,omitempty"`
	RegistrationEnabled     bool                 `json:"registration_enabled,omitempty"`
	PasswordRecoveryEnabled bool                 `json:"password_recovery_enabled,omitempty"`
	MfaEnabled              bool                 `json:"mfa_enabled,omitempty"`
	PublicLinks []Link `json:"public_links,omitempty"`
	PrivateLinks []Link `json:"private_links,omitempty"`
	Realms []UserRealm `json:"realms,omitempty"`
	ActionEndpoint string `json:"-"`
	CustomCSSPath  string `json:"custom_css_path,omitempty"`
	CustomJsPath   string `json:"custom_js_path,omitempty"`
}
type Template struct {
	Alias string `json:"alias,omitempty"`
	Path     string             `json:"path,omitempty"`
	Template *template.Template `json:"-"`
}
type UserRealm struct {
	Name  string `json:"name,omitempty"`
	Label string `json:"label,omitempty"`
}
type Args struct {
	Title                   string
	LogoURL                 string
	LogoDescription         string
	ActionEndpoint          string
	Message                 string
	MessageType             string
	PublicLinks             []Link
	PrivateLinks            []Link
	Realms                  []UserRealm
	Authenticated           bool
	Data                    map[string]interface{}
	RegistrationEnabled     bool
	PasswordRecoveryEnabled bool
	MfaEnabled              bool
	CustomCSSEnabled        bool
	CustomJsEnabled         bool
}
func NewFactory() *Factory {
	return &Factory{
		LogoURL:         "/assets/images/logo.svg",
		LogoDescription: "Authentication Portal",
		Templates:       make(map[string]*Template),
		PublicLinks:     []Link{},
		PrivateLinks:    []Link{},
		Realms:          []UserRealm{},
	}
}
func NewTemplate(s, tp string) (*Template, error) {
	var templateBody string
	if s == "" {
		return nil, fmt.Errorf("the user interface alias cannot be empty")
	}
	if tp == "" {
		return nil, fmt.Errorf("the path to user interface template cannot be empty")
	}
	tmpl := &Template{
		Alias: s,
		Path:  tp,
	}
	if tp == "inline" {
		if _, exists := PageTemplates[s]; !exists {
			return nil, fmt.Errorf("built-in template does not exists: %s", s)
		}
		templateBody = PageTemplates[s]
	} else {
		if strings.HasPrefix(tp, "http://") || strings.HasPrefix(tp, "https://") {
			return nil, fmt.Errorf("the loading of template from remote URL is not supported yet")
		}
		content, err := ioutil.ReadFile(tp)
		if err != nil {
			return nil, fmt.Errorf("failed to load %s template from %s: %s", s, tp, err)
		}
		templateBody = string(content)
	}
	t, err := loadTemplateFromString(s, templateBody)
	if err != nil {
		return nil, fmt.Errorf("Failed to load %s template from %s: %s", s, tp, err)
	}
	tmpl.Template = t
	return tmpl, nil
}
func (f *Factory) GetArgs() *Args {
	args := &Args{
		Title:                   f.Title,
		LogoURL:                 f.LogoURL,
		LogoDescription:         f.LogoDescription,
		PublicLinks:             f.PublicLinks,
		PrivateLinks:            f.PrivateLinks,
		Realms:                  f.Realms,
		ActionEndpoint:          f.ActionEndpoint,
		Data:                    make(map[string]interface{}),
		RegistrationEnabled:     f.RegistrationEnabled,
		PasswordRecoveryEnabled: f.PasswordRecoveryEnabled,
		MfaEnabled:              f.MfaEnabled,
	}
	uiOptions := make(map[string]interface{})
	if f.CustomCSSPath != "" {
		args.CustomCSSEnabled = true
		uiOptions["custom_css_required"] = "yes"
	} else {
		uiOptions["custom_css_required"] = "no"
	}
	if f.CustomJsPath != "" {
		args.CustomJsEnabled = true
		uiOptions["custom_js_required"] = "yes"
	} else {
		uiOptions["custom_js_required"] = "no"
	}
	args.Data["ui_options"] = uiOptions
	return args
}
func (args *Args) BaseURL(s string) {
	if !strings.HasPrefix(args.LogoURL, "http") {
		args.LogoURL = path.Join(s, args.LogoURL)
	}
	args.ActionEndpoint = s
}
func (args *Args) AddFrontendLinks(arr []string) {
	for _, encodedArgs := range arr {
		parts, err := cfgutils.DecodeArgs(encodedArgs)
		if err != nil {
			continue
		}
		lnk := Link{
			Title: parts[0],
			Link:  parts[1],
		}
		argp := 2
		var disabledLink bool
		for argp < len(parts) {
			switch parts[argp] {
			case "target_blank":
				lnk.Target = "_blank"
				lnk.TargetEnabled = true
			case "icon":
				argp++
				if argp < len(parts) {
					lnk.IconName = parts[argp]
					lnk.IconEnabled = true
				}
			case "disabled":
				disabledLink = true
				break
			}
			argp++
		}
		if disabledLink {
			continue
		}
		args.PrivateLinks = append(args.PrivateLinks, lnk)
	}
}