2020-08-01 23:05:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2020-11-02 00:53:08 +00:00
|
|
|
"github.com/hrfee/jfa-go/common"
|
|
|
|
"github.com/hrfee/jfa-go/jfapi"
|
2020-08-01 23:05:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type testReq struct {
|
|
|
|
Host string `json:"jfHost"`
|
|
|
|
Username string `json:"jfUser"`
|
|
|
|
Password string `json:"jfPassword"`
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) TestJF(gc *gin.Context) {
|
2020-08-01 23:05:35 +00:00
|
|
|
var req testReq
|
|
|
|
gc.BindJSON(&req)
|
2020-11-02 23:26:46 +00:00
|
|
|
tempjf, _ := jfapi.NewJellyfin(req.Host, "jfa-go-setup", app.version, "auth", "auth", common.NewTimeoutHandler("authJF", req.Host, true), 30)
|
2020-11-02 00:53:08 +00:00
|
|
|
_, status, err := tempjf.Authenticate(req.Username, req.Password)
|
2020-08-01 23:05:35 +00:00
|
|
|
if !(status == 200 || status == 204) || err != nil {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.info.Printf("Auth failed with code %d (%s)", status, err)
|
2020-08-01 23:05:35 +00:00
|
|
|
gc.JSON(401, map[string]bool{"success": false})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
gc.JSON(200, map[string]bool{"success": true})
|
|
|
|
}
|