(c *context.Context, f form.Install)
| 184 | } |
| 185 | |
| 186 | func InstallPost(c *context.Context, f form.Install) { |
| 187 | c.Data["CurDbOption"] = f.DbType |
| 188 | |
| 189 | if c.HasError() { |
| 190 | if c.HasValue("Err_SMTPEmail") { |
| 191 | c.FormErr("SMTP") |
| 192 | } |
| 193 | if c.HasValue("Err_AdminName") || |
| 194 | c.HasValue("Err_AdminPasswd") || |
| 195 | c.HasValue("Err_AdminEmail") { |
| 196 | c.FormErr("Admin") |
| 197 | } |
| 198 | c.HTML(http.StatusBadRequest, INSTALL) |
| 199 | return |
| 200 | } |
| 201 | |
| 202 | if _, err := exec.LookPath("git"); err != nil { |
| 203 | c.RenderWithErr(c.Tr("install.test_git_failed", err), http.StatusInternalServerError, INSTALL, &f) |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | // Pass basic check, now test configuration. |
| 208 | // Test database setting. |
| 209 | dbTypes := map[string]string{ |
| 210 | "PostgreSQL": "postgres", |
| 211 | "MySQL": "mysql", |
| 212 | "SQLite3": "sqlite3", |
| 213 | } |
| 214 | conf.Database.Type = dbTypes[f.DbType] |
| 215 | conf.Database.Host = f.DbHost |
| 216 | conf.Database.User = f.DbUser |
| 217 | conf.Database.Password = f.DbPasswd |
| 218 | conf.Database.Name = f.DbName |
| 219 | conf.Database.Schema = f.DbSchema |
| 220 | conf.Database.SSLMode = f.SSLMode |
| 221 | conf.Database.Path = f.DbPath |
| 222 | |
| 223 | if conf.Database.Type == "sqlite3" && conf.Database.Path == "" { |
| 224 | c.FormErr("DbPath") |
| 225 | c.RenderWithErr(c.Tr("install.err_empty_db_path"), http.StatusBadRequest, INSTALL, &f) |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | // Set test engine. |
| 230 | if err := database.NewTestEngine(); err != nil { |
| 231 | if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { |
| 232 | c.FormErr("DbType") |
| 233 | c.RenderWithErr(c.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), http.StatusInternalServerError, INSTALL, &f) |
| 234 | } else { |
| 235 | c.FormErr("DbSetting") |
| 236 | c.RenderWithErr(c.Tr("install.invalid_db_setting", err), http.StatusBadRequest, INSTALL, &f) |
| 237 | } |
| 238 | return |
| 239 | } |
| 240 | |
| 241 | // Test repository root path. |
| 242 | f.RepoRootPath = strings.ReplaceAll(f.RepoRootPath, "\\", "/") |
| 243 | if err := os.MkdirAll(f.RepoRootPath, os.ModePerm); err != nil { |
nothing calls this directly
no test coverage detected