Support changing default landing path

This adds a new `landing` value in the [app] section of config.ini.
If non-empty, unauthenticated users on multi-user instances will be
redirected to the path given there.

This closes T574
pull/102/head
Matt Baer 6 years ago
parent 77c8152786
commit 584fe4fb93
  1. 5
      app.go
  2. 9
      config/config.go

@ -31,6 +31,7 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/writeas/go-strip-markdown" "github.com/writeas/go-strip-markdown"
"github.com/writeas/impart"
"github.com/writeas/web-core/auth" "github.com/writeas/web-core/auth"
"github.com/writeas/web-core/converter" "github.com/writeas/web-core/converter"
"github.com/writeas/web-core/log" "github.com/writeas/web-core/log"
@ -90,6 +91,10 @@ func handleViewHome(app *App, w http.ResponseWriter, r *http.Request) error {
return handleViewPad(app, w, r) return handleViewPad(app, w, r)
} }
if land := app.cfg.App.LandingPath(); land != "/" {
return impart.HTTPError{http.StatusFound, land}
}
p := struct { p := struct {
page.StaticPage page.StaticPage
Flashes []template.HTML Flashes []template.HTML

@ -13,6 +13,7 @@ package config
import ( import (
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
"strings"
) )
const ( const (
@ -64,6 +65,7 @@ type (
Theme string `ini:"theme"` Theme string `ini:"theme"`
JSDisabled bool `ini:"disable_js"` JSDisabled bool `ini:"disable_js"`
WebFonts bool `ini:"webfonts"` WebFonts bool `ini:"webfonts"`
Landing string `ini:"landing"`
// Users // Users
SingleUser bool `ini:"single_user"` SingleUser bool `ini:"single_user"`
@ -134,6 +136,13 @@ func (cfg *Config) IsSecureStandalone() bool {
return cfg.Server.Port == 443 && cfg.Server.TLSCertPath != "" && cfg.Server.TLSKeyPath != "" return cfg.Server.Port == 443 && cfg.Server.TLSCertPath != "" && cfg.Server.TLSKeyPath != ""
} }
func (ac *AppCfg) LandingPath() string {
if !strings.HasPrefix(ac.Landing, "/") {
return "/" + ac.Landing
}
return ac.Landing
}
// Load reads the given configuration file, then parses and returns it as a Config. // Load reads the given configuration file, then parses and returns it as a Config.
func Load(fname string) (*Config, error) { func Load(fname string) (*Config, error) {
if fname == "" { if fname == "" {

Loading…
Cancel
Save