mirror of
https://github.com/documize/community.git
synced 2025-07-23 15:19:42 +02:00
improved setup wizard redirection
This commit is contained in:
parent
8081b60146
commit
d3512b499a
15 changed files with 670 additions and 661 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/api/plugins"
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
|
@ -32,8 +33,8 @@ type Handler struct {
|
|||
Store *domain.Store
|
||||
}
|
||||
|
||||
// Create the tables in a blank database
|
||||
func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
// Setup the tables in a blank database
|
||||
func (h *Handler) Setup(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
target := "/setup"
|
||||
status := http.StatusBadRequest
|
||||
|
@ -45,7 +46,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
req, err := http.NewRequest("GET", target, nil)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("database.Create()'s error in defer ", err)
|
||||
h.Runtime.Log.Error("database.Setup error in defer ", err)
|
||||
}
|
||||
|
||||
http.Redirect(w, req, target, status)
|
||||
|
@ -53,7 +54,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("database.Create()'s r.ParseForm()", err)
|
||||
h.Runtime.Log.Error("database.Setup r.ParseForm()", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
|||
dbhash := r.Form.Get("dbhash")
|
||||
|
||||
if dbname != web.SiteInfo.DBname || dbhash != web.SiteInfo.DBhash {
|
||||
h.Runtime.Log.Error("database.Create()'s security credentials error ", errors.New("bad db name or validation code"))
|
||||
h.Runtime.Log.Error("database.Setup security credentials error ", errors.New("bad db name or validation code"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -84,22 +85,27 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
|||
details.Password == "" ||
|
||||
details.Firstname == "" ||
|
||||
details.Lastname == "" {
|
||||
h.Runtime.Log.Error("database.Create() error ", errors.New("required field in database set-up form blank"))
|
||||
h.Runtime.Log.Error("database.Setup error ", errors.New("required field in database set-up form blank"))
|
||||
return
|
||||
}
|
||||
|
||||
if err = Migrate(h.Runtime, false /* no tables exist yet */); err != nil {
|
||||
h.Runtime.Log.Error("database.Create()", err)
|
||||
h.Runtime.Log.Error("database.Setup migrate", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = setupAccount(h.Runtime, details, secrets.GenerateSalt())
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("database.Create()", err)
|
||||
h.Runtime.Log.Error("database.Setup setup account ", err)
|
||||
return
|
||||
}
|
||||
|
||||
h.Runtime.Flags.SiteMode = env.SiteModeNormal
|
||||
|
||||
err = plugins.Setup(h.Store)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("database.Setup plugin setup failed", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The result of completing the onboarding process.
|
|
@ -268,6 +268,7 @@ func getStatements(bytes []byte) []string {
|
|||
stripped := regexp.MustCompile("(?s)--.*?\n|/\\*.*?\\*/").ReplaceAll(bytes, []byte("\n"))
|
||||
sqls := strings.Split(string(stripped), ";")
|
||||
ret := make([]string, 0, len(sqls))
|
||||
|
||||
for _, v := range sqls {
|
||||
trimmed := strings.TrimSpace(v)
|
||||
if len(trimmed) > 0 &&
|
||||
|
@ -275,5 +276,6 @@ func getStatements(bytes []byte) []string {
|
|||
ret = append(ret, trimmed+";")
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue