From af61549bf155cf0a3b156426f1df3b8decfbd1d6 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 2 May 2021 13:23:59 +0100 Subject: [PATCH] ombi: reset password when using pwr links When password reset links are enabled, the ombi password will be reset to the PIN along with Jellyfin. --- config/config-base.json | 6 +++--- html/password-reset.html | 4 ++++ lang/pwreset/en-us.json | 1 + ombi/ombi.go | 2 +- views.go | 22 +++++++++++++++++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/config/config-base.json b/config/config-base.json index 71c0f97..5cd3838 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -469,13 +469,13 @@ "description": "Path to the folder Jellyfin puts password-reset files." }, "link_reset": { - "name": "Use reset link instead of PIN", + "name": "Use reset link instead of PIN (Required for Ombi)", "required": false, "requires_restart": true, "depends_true": "enabled", "type": "bool", "value": false, - "description": "Send users a link to reset their password instead of a PIN." + "description": "Send users a link to reset their password instead of a PIN. Must be enabled to reset Ombi password at the same time as the Jellyfin password." }, "language": { "name": "Default reset link language", @@ -722,7 +722,7 @@ "order": [], "meta": { "name": "Ombi Integration", - "description": "Connect to Ombi to automatically create both Ombi and Jellyfin accounts for new users. You'll need to create a user template for this to work. Once enabled, refresh to see an option in settings for this." + "description": "Connect to Ombi to automatically create both Ombi and Jellyfin accounts for new users. You'll need to create a user template for this to work. Once enabled, refresh to see an option in settings for this. To handle password resets for Ombi & Jellyfin, enable \"Use reset link instead of PIN\"." }, "settings": { "enabled": { diff --git a/html/password-reset.html b/html/password-reset.html index a0f6598..6013028 100644 --- a/html/password-reset.html +++ b/html/password-reset.html @@ -22,7 +22,11 @@

{{ if .success }} + {{ if .ombiEnabled }} + {{ .strings.youCanLoginOmbi }} + {{ else }} {{ .strings.youCanLogin }} + {{ end }} {{ else }} {{ .strings.tryAgain }} {{ end }} diff --git a/lang/pwreset/en-us.json b/lang/pwreset/en-us.json index c04fb77..cf6ba1e 100644 --- a/lang/pwreset/en-us.json +++ b/lang/pwreset/en-us.json @@ -7,6 +7,7 @@ "resetFailed": "Password reset failed", "tryAgain": "Please try again.", "youCanLogin": "You can now log in with the below code as your password.", + "youCanLoginOmbi": "You can now log in to Jellyfin & Ombi with the below code as your password.", "changeYourPassword": "Make sure to change your password after you log in." } } diff --git a/ombi/ombi.go b/ombi/ombi.go index b045d26..a64122a 100644 --- a/ombi/ombi.go +++ b/ombi/ombi.go @@ -130,7 +130,7 @@ func (ombi *Ombi) ModifyUser(user map[string]interface{}) (status int, err error err = fmt.Errorf("No ID provided") return } - _, status, err = ombi.put(ombi.server+"/api/v1/Identity", user, false) + _, status, err = ombi.put(ombi.server+"/api/v1/Identity/", user, false) return } diff --git a/views.go b/views.go index 0ebb212..6affd6a 100644 --- a/views.go +++ b/views.go @@ -144,6 +144,7 @@ func (app *appContext) ResetPassword(gc *gin.Context) { "contactMessage": app.config.Section("ui").Key("contact_message").String(), "strings": app.storage.lang.PasswordReset[lang].Strings, "success": false, + "ombiEnabled": app.config.Section("ombi").Key("enabled").MustBool(false), } resp, status, err := app.jf.ResetPassword(pin) if status == 200 && err == nil && resp.Success { @@ -152,7 +153,26 @@ func (app *appContext) ResetPassword(gc *gin.Context) { } else { app.err.Printf("Password Reset failed (%d): %v", status, err) } - gcHTML(gc, http.StatusOK, "password-reset.html", data) + defer gcHTML(gc, http.StatusOK, "password-reset.html", data) + if app.config.Section("ombi").Key("enabled").MustBool(false) { + jfUser, status, err := app.jf.UserByName(resp.UsersReset[0], false) + if status != 200 || err != nil { + app.err.Printf("Failed to get user \"%s\" from jellyfin/emby (%d): %v", resp.UsersReset[0], status, err) + return + } + ombiUser, status, err := app.getOmbiUser(jfUser.ID) + if status != 200 || err != nil { + app.err.Printf("Failed to get user \"%s\" from ombi (%d): %v", resp.UsersReset[0], status, err) + return + } + ombiUser["password"] = pin + status, err = app.ombi.ModifyUser(ombiUser) + if status != 200 || err != nil { + app.err.Printf("Failed to set password for ombi user \"%s\" (%d): %v", ombiUser["userName"], status, err) + return + } + app.debug.Printf("Reset password for ombi user \"%s\"", ombiUser["userName"]) + } } func (app *appContext) InviteProxy(gc *gin.Context) {