Exemplo n.º 1
0
// BaseCurrencyCode retrieves application base currency code
func BaseCurrencyCode(cr config.Reader) (language.Currency, error) {
	base, err := cr.GetString(config.Path(PathCurrencyBase))
	if config.NotKeyNotFoundError(err) {
		return language.Currency{}, err
	}
	return language.ParseCurrency(base)
}
Exemplo n.º 2
0
// WithPasswordFromConfig retrieves the password from the configuration with path
// as defined in constant PathJWTPassword
func WithPasswordFromConfig(cr config.Reader) Option {
	pw, err := cr.GetString(config.Path(PathJWTPassword))
	if config.NotKeyNotFoundError(err) {
		pw = string(uuid.NewRandom())
	}
	return WithPassword([]byte(pw))
}
Exemplo n.º 3
0
// AllowedCurrencies returns all installed currencies from global scope.
func AllowedCurrencies(cr config.Reader) ([]string, error) {
	installedCur, err := cr.GetString(config.Path(PathSystemCurrencyInstalled))
	if config.NotKeyNotFoundError(err) {
		return nil, err
	}
	// TODO use internal model of PathSystemCurrencyInstalled defined in package directory
	return strings.Split(installedCur, ","), nil
}
Exemplo n.º 4
0
func (u *User) Authenticate(cr config.Reader, h crypto.Hasher, username, password string) error {
	isCaseSensitive := cr.GetBool(config.Path("admin/security/use_case_sensitive_login"))

	if !isCaseSensitive {
		// ... hmm
	}

	return nil
}
Exemplo n.º 5
0
// IsSecure checks if a request has been sent over a TLS connection. Also checks
// if the app runs behind a proxy server and therefore checks the off loader header.
func IsSecure(cr config.Reader, r *http.Request) bool {
	// due to import cycle this function must be in this package
	if r.TLS != nil {
		return true
	}

	oh, err := cr.GetString(config.Path(PathOffloaderHeader), config.ScopeDefault())
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("net.httputils.IsSecure.FromContextReader.GetString", "err", err, "path", PathOffloaderHeader)
		}
		return false
	}

	h := r.Header.Get(oh)
	hh := r.Header.Get("HTTP_" + oh)

	var isHTTPS bool
	switch "https" {
	case h, hh:
		isHTTPS = true
	}
	return isHTTPS
}
Exemplo n.º 6
0
// BaseCurrencyCode retrieves application base currency code
func BaseCurrencyCode(cr config.Reader) (language.Currency, error) {
	return language.ParseCurrency(cr.GetString(config.Path(PathCurrencyBase)))
}
Exemplo n.º 7
0
// ShowNonRequiredState
func ShowNonRequiredState(cr config.Reader, r scope.StoreIDer) bool {
	return cr.GetBool(config.ScopeStore(r.StoreID()), config.Path(PathDisplayAllStates))
}
Exemplo n.º 8
0
// DefaultCountry returns the country code. Store argument is optional.
func DefaultCountry(cr config.Reader, r config.ScopeIDer) string {
	return cr.GetString(config.Path(PathDefaultCountry), config.ScopeStore(r))
}
Exemplo n.º 9
0
// SetPasswordFromConfig retrieves the password from the configuration with path
// as defined in constant PathJWTPassword
func SetPasswordFromConfig(cr config.Reader) OptionFunc {
	pw := cr.GetString(config.Path(PathJWTPassword))
	return SetPassword([]byte(pw))
}