mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Add option to skip admin creation if the database appears to be provisioned already
This commit is contained in:
parent
062cafc4f2
commit
8c14bf18d7
3 changed files with 36 additions and 20 deletions
|
@ -126,7 +126,7 @@ func (dbf *dbForm) validate() (status dbStatus, err error) {
|
|||
return dbStatusUnknown, errors.New("max lifetime for connections must be greater than 0")
|
||||
}
|
||||
|
||||
if err := gcsql.ConnectToDB(&config.SQLConfig{
|
||||
sqlConfig := config.SQLConfig{
|
||||
// using a dummy config to test connection. It will be set as the main config later
|
||||
DBtype: dbf.DBtype,
|
||||
DBhost: dbf.DBhost,
|
||||
|
@ -139,9 +139,15 @@ func (dbf *dbForm) validate() (status dbStatus, err error) {
|
|||
DBMaxOpenConnections: dbf.MaxOpenConns,
|
||||
DBMaxIdleConnections: dbf.MaxIdleConns,
|
||||
DBConnMaxLifetimeMin: dbf.ConnMaxLifetimeMin,
|
||||
}); err != nil {
|
||||
}
|
||||
if err := gcsql.ConnectToDB(&sqlConfig); err != nil {
|
||||
return dbStatusUnknown, err
|
||||
}
|
||||
|
||||
systemCriticalCfg := config.GetSystemCriticalConfig()
|
||||
systemCriticalCfg.SQLConfig = sqlConfig
|
||||
config.SetSystemCriticalConfig(systemCriticalCfg)
|
||||
|
||||
tablesExist, err := gcsql.DoesGochanPrefixTableExist()
|
||||
if err != nil {
|
||||
return dbStatusUnknown, err
|
||||
|
|
|
@ -45,7 +45,7 @@ func (dbs dbStatus) String() string {
|
|||
case dbStatusNoPrefix:
|
||||
return "Since no prefix was specified, the installer will attempt to provision the database in the next step."
|
||||
case dbStatusTablesExist:
|
||||
return fmt.Sprintf("The database appears to contain Gochan tables with the prefix %s. The next step (database provisioning) may return errors", config.GetSystemCriticalConfig().DBprefix)
|
||||
return fmt.Sprintf("The database appears to contain Gochan tables with the prefix %s. Gochan will attempt to use these tables instead of provisioning the database, and admin account creation may be skipped.", config.GetSystemCriticalConfig().DBprefix)
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ func installHandler(writer http.ResponseWriter, req bunrouter.Request) (err erro
|
|||
"page": page,
|
||||
"config": cfg,
|
||||
"nextButton": "Next",
|
||||
"skipButton": false,
|
||||
}
|
||||
|
||||
refererResult, err := serverutil.CheckReferer(req.Request)
|
||||
|
@ -162,8 +163,12 @@ func installHandler(writer http.ResponseWriter, req bunrouter.Request) (err erro
|
|||
data["alreadyCreated"] = true
|
||||
break
|
||||
}
|
||||
if currentDBStatus == dbStatusTablesExist {
|
||||
// If the database already has tables, allow the user to skip creating an admin account
|
||||
data["skipButton"] = true
|
||||
}
|
||||
|
||||
// staff not created yet, show new admin form
|
||||
// database not properly initialized
|
||||
if currentDBStatus == dbStatusUnknown {
|
||||
httpStatus = http.StatusBadRequest
|
||||
errEv.Msg("Database status is unknown, cannot proceed with provisioning")
|
||||
|
@ -187,23 +192,25 @@ func installHandler(writer http.ResponseWriter, req bunrouter.Request) (err erro
|
|||
case "pre-save":
|
||||
pageTitle = "Configuration Confirmation"
|
||||
|
||||
var staffFormData staffForm
|
||||
if err = forms.FillStructFromForm(req.Request, &staffFormData); err != nil {
|
||||
httpStatus = http.StatusBadRequest
|
||||
errEv.Err(err).Msg("Failed to fill form data")
|
||||
return
|
||||
}
|
||||
if err = staffFormData.validate(); err != nil {
|
||||
httpStatus = http.StatusBadRequest
|
||||
warnEv.Err(err).Msg("Invalid staff form data")
|
||||
return
|
||||
}
|
||||
if req.PostFormValue("skip") == "" {
|
||||
var staffFormData staffForm
|
||||
if err = forms.FillStructFromForm(req.Request, &staffFormData); err != nil {
|
||||
httpStatus = http.StatusBadRequest
|
||||
errEv.Err(err).Msg("Failed to fill form data")
|
||||
return
|
||||
}
|
||||
if err = staffFormData.validate(); err != nil {
|
||||
httpStatus = http.StatusBadRequest
|
||||
warnEv.Err(err).Msg("Invalid staff form data")
|
||||
return
|
||||
}
|
||||
|
||||
adminUser, err = gcsql.NewStaff(staffFormData.Username, staffFormData.Password, 3)
|
||||
if err != nil {
|
||||
httpStatus = http.StatusInternalServerError
|
||||
errEv.Err(err).Msg("Failed to create administrator account")
|
||||
return err
|
||||
adminUser, err = gcsql.NewStaff(staffFormData.Username, staffFormData.Password, 3)
|
||||
if err != nil {
|
||||
httpStatus = http.StatusInternalServerError
|
||||
errEv.Err(err).Msg("Failed to create administrator account")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if configPath == "" {
|
||||
|
|
|
@ -112,6 +112,9 @@
|
|||
{{- if ne .nextPage "" -}}
|
||||
<section class="buttons">
|
||||
<input type="submit" value="{{.nextButton}}" />
|
||||
{{- if .skipButton -}}
|
||||
<input type="submit" name="skip" value="Skip" />
|
||||
{{- end -}}
|
||||
</section>
|
||||
{{- end -}}
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue