From 22c91be12770473fbed2e0566589a43fc290452a Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Thu, 22 Jun 2023 12:33:40 +0100 Subject: [PATCH] userpage: make pwr accept username too --- api-userpage.go | 4 ++-- config/config-base.json | 2 +- email.go | 8 +++++++- html/user.html | 2 +- lang/form/en-us.json | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/api-userpage.go b/api-userpage.go index 3097b5e..f129a08 100644 --- a/api-userpage.go +++ b/api-userpage.go @@ -478,7 +478,7 @@ func (app *appContext) UnlinkMyMatrix(gc *gin.Context) { respondBool(200, true, gc) } -// @Summary Generate & send a password reset link if the given email/contact method exists. Doesn't give you any info about it's success. +// @Summary Generate & send a password reset link if the given username/email/contact method exists. Doesn't give you any info about it's success. // @Produce json // @Param address path string true "address/contact method associated w/ your account." // @Success 204 {object} boolResponse @@ -502,7 +502,7 @@ func (app *appContext) ResetMyPassword(gc *gin.Context) { var pwr InternalPWR var err error - jfID := app.reverseUserSearch(address) + jfID := app.ReverseUserSearch(address) if jfID == "" { app.debug.Printf("Ignoring PWR request: User not found") diff --git a/config/config-base.json b/config/config-base.json index c0fb5f8..c8e08af 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -377,7 +377,7 @@ "order": [], "meta": { "name": "User Page", - "description": "Settings for the user page, which provides useful info and tools to users directly.", + "description": "The User Page (My Account) allows users to access and modify info directly, such as changing/adding contact methods, seeing their expiry date, or changing their password. Password resets can also be initiated from here, given a contact method or username. ", "depends_true": "ui|jellyfin_login" }, "settings": { diff --git a/email.go b/email.go index dda9428..4ee8f36 100644 --- a/email.go +++ b/email.go @@ -872,7 +872,13 @@ func (app *appContext) getAddressOrName(jfID string) string { return "" } -func (app *appContext) reverseUserSearch(address string) string { +// ReverseUserSearch returns the jellyfin ID of the user with the given username, email, or contact method username. +// returns "" if none found. returns only the first match, might be an issue if there are users with the same contact method usernames. +func (app *appContext) ReverseUserSearch(address string) string { + user, status, err := app.jf.UserByName(address, false) + if status == 200 && err == nil { + return user.ID + } for id, email := range app.storage.GetEmails() { if strings.ToLower(address) == strings.ToLower(email.Addr) { return id diff --git a/html/user.html b/html/user.html index b709969..2c5cf5d 100644 --- a/html/user.html +++ b/html/user.html @@ -56,7 +56,7 @@ {{ end }}

- +
{{ if .linkResetEnabled }} diff --git a/lang/form/en-us.json b/lang/form/en-us.json index 5b30b33..23a120c 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -29,9 +29,9 @@ "userPageSuccessMessage": "You can see and change details about your account later on the {myAccount} page.", "resetPassword": "Reset Password", "resetPasswordThroughJellyfin": "To reset your password, visit {jfLink} and press the \"Forgot Password\" button.", - "resetPasswordThroughLink": "To reset your password, enter your email address or a linked contact method username, and submit. A link will be sent to reset your password.", + "resetPasswordThroughLink": "To reset your password, enter your username, email address or a linked contact method username, and submit. A link will be sent to reset your password.", "resetSent": "Reset Sent.", - "resetSentDescription": "If an account with the given contact method exists, a password reset link has been sent to all contact methods available. The code will expire in 30 minutes." + "resetSentDescription": "If an account with the given username/contact method exists, a password reset link has been sent via all contact methods available. The code will expire in 30 minutes." }, "notifications": { "errorUserExists": "User already exists.",