From 9693ce3dcd0671ee59f17fff69f2c8b05da6026b Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 27 Jul 2021 16:48:24 +0100 Subject: [PATCH] settings: add redundant URL base for pwr having it under "Invite Emails" when they weren't in use was confusing. If only one is set in the config file, it'll be used for both. --- api.go | 9 +++++++++ config.go | 7 +++++++ config/config-base.json | 11 ++++++++++- email.go | 11 +++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/api.go b/api.go index bc1e575..2966244 100644 --- a/api.go +++ b/api.go @@ -1722,6 +1722,15 @@ func (app *appContext) GetConfig(gc *gin.Context) { resp.Sections["discord"].Settings["language"] = tl resp.Sections["matrix"].Settings["language"] = tl + // if setting := resp.Sections["invite_emails"].Settings["url_base"]; setting.Value == "" { + // setting.Value = strings.TrimSuffix(resp.Sections["password_resets"].Settings["url_base"].Value.(string), "/invite") + // resp.Sections["invite_emails"].Settings["url_base"] = setting + // } + // if setting := resp.Sections["password_resets"].Settings["url_base"]; setting.Value == "" { + // setting.Value = strings.TrimSuffix(resp.Sections["invite_emails"].Settings["url_base"].Value.(string), "/invite") + // resp.Sections["password_resets"].Settings["url_base"] = setting + // } + gc.JSON(200, resp) } diff --git a/config.go b/config.go index e3a8032..64a60b5 100644 --- a/config.go +++ b/config.go @@ -97,6 +97,13 @@ func (app *appContext) loadConfig() error { app.config.Section("jellyfin").Key("version").SetValue(version) app.config.Section("jellyfin").Key("device").SetValue("jfa-go") app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", version, commit)) + + // These two settings are pretty much the same + url1 := app.config.Section("invite_emails").Key("url_base").String() + url2 := app.config.Section("password_resets").Key("url_base").String() + app.MustSetValue("password_resets", "url_base", strings.TrimSuffix(url1, "/invite")) + app.MustSetValue("invite_emails", "url_base", url2) + messagesEnabled = app.config.Section("messages").Key("enabled").MustBool(false) telegramEnabled = app.config.Section("telegram").Key("enabled").MustBool(false) discordEnabled = app.config.Section("discord").Key("enabled").MustBool(false) diff --git a/config/config-base.json b/config/config-base.json index ac386ae..7311021 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -803,6 +803,15 @@ "value": false, "description": "Instead of automatically setting the user's password to the PIN, allow them to set a new password through the reset link." }, + "url_base": { + "name": "URL Base", + "required": true, + "requires_restart": false, + "depends_true": "link_reset", + "type": "text", + "value": "http://accounts.jellyf.in:8056", + "description": "Base URL for jfa-go. You can leave this if you have one set in \"Invite Emails\". This is necessary because using a reverse proxy means the program has no way of knowing the URL itself." + }, "language": { "name": "Default reset link language", "required": false, @@ -896,7 +905,7 @@ "requires_restart": false, "depends_true": "enabled", "type": "text", - "value": "http://accounts.jellyf.in:8056/invite", + "value": "http://accounts.jellyf.in:8056", "description": "Base URL for jfa-go. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself." } } diff --git a/email.go b/email.go index de6fdd1..0556695 100644 --- a/email.go +++ b/email.go @@ -369,6 +369,9 @@ func (emailer *Emailer) inviteValues(code string, invite Invite, app *appContext d, t, expiresIn := emailer.formatExpiry(expiry, false, app.datePattern, app.timePattern) message := app.config.Section("messages").Key("message").String() inviteLink := app.config.Section("invite_emails").Key("url_base").String() + if !strings.HasSuffix(inviteLink, "/invite") { + inviteLink += "/invite" + } inviteLink = fmt.Sprintf("%s/%s", inviteLink, code) template := map[string]interface{}{ "hello": emailer.lang.InviteEmail.get("hello"), @@ -540,17 +543,17 @@ func (emailer *Emailer) resetValues(pwr PasswordReset, app *appContext, noSub bo } else { template["helloUser"] = emailer.lang.Strings.template("helloUser", tmpl{"username": pwr.Username}) template["codeExpiry"] = emailer.lang.PasswordReset.template("codeExpiry", tmpl{"date": d, "time": t, "expiresInMinutes": expiresIn}) - inviteLink := app.config.Section("invite_emails").Key("url_base").String() + url := app.config.Section("password_resets").Key("url_base").String() if linkResetEnabled { - if inviteLink != "" { + if url != "" { // Strip /invite form end of this URL, ik its ugly. template["link_reset"] = true - pinLink := fmt.Sprintf("%s/reset?pin=%s", strings.TrimSuffix(inviteLink, "/invite"), pwr.Pin) + pinLink := fmt.Sprintf("%s/reset?pin=%s", url, pwr.Pin) template["pin"] = pinLink // Only used in html email. template["pin_code"] = pwr.Pin } else { - app.info.Println("Password Reset link disabled as no URL Base provided. Set in Settings > Invite Emails.") + app.info.Println("Password Reset link disabled as no URL Base provided. Set in Settings > Password Resets.") template["pin"] = pwr.Pin } } else {