setup: add descriptive "test connection" messages; disable next button

for #129.
This commit is contained in:
Harvey Tindall
2021-07-24 14:15:10 +01:00
parent 6551eeb938
commit 27ad7a4cf7
3 changed files with 59 additions and 27 deletions
+22 -2
View File
@@ -55,15 +55,35 @@ type testReq struct {
func (app *appContext) TestJF(gc *gin.Context) {
var req testReq
gc.BindJSON(&req)
if !(strings.HasPrefix(req.Server, "http://") || strings.HasPrefix(req.Server, "https://")) {
req.Server = "http://" + req.Server
}
serverType := mediabrowser.JellyfinServer
if req.ServerType == "emby" {
serverType = mediabrowser.EmbyServer
}
tempjf, _ := mediabrowser.NewServer(serverType, req.Server, "jfa-go-setup", app.version, "auth", "auth", mediabrowser.NewNamedTimeoutHandler("authJF", req.Server, true), 30)
_, status, err := tempjf.Authenticate(req.Username, req.Password)
user, status, err := tempjf.Authenticate(req.Username, req.Password)
if !(status == 200 || status == 204) || err != nil {
msg := ""
switch status {
case 401:
msg = "errorInvalidUserPass"
case 403:
msg = "errorUserDisabled"
case 404:
msg = "error404"
}
app.info.Printf("Auth failed with code %d (%s)", status, err)
gc.JSON(401, map[string]bool{"success": false})
if msg != "" {
respond(status, msg, gc)
} else {
respondBool(status, false, gc)
}
return
}
if !user.Policy.IsAdministrator {
respond(403, "errorNotAdmin", gc)
return
}
gc.JSON(200, map[string]bool{"success": true})