1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

add option to auto redirect to jellyfin (or given link)

if enabled (General>Auto redirect on success), the user will not have to
    click "continue" on the form or creation success page and will
    insted be redirected. For #242.
This commit is contained in:
Harvey Tindall 2023-02-02 10:34:22 +00:00
parent de6bc02ad8
commit eb85ee4d35
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 55 additions and 38 deletions

View File

@ -272,6 +272,7 @@
"requires_restart": true, "requires_restart": true,
"type": "bool", "type": "bool",
"value": false, "value": false,
"advanced": true,
"description": "Navigate directly to the above URL instead of needing the user to click \"Continue\"." "description": "Navigate directly to the above URL instead of needing the user to click \"Continue\"."
} }
} }

View File

@ -8,6 +8,9 @@
{{ else }} {{ else }}
<title>{{ .strings.pageTitle }}</title> <title>{{ .strings.pageTitle }}</title>
{{ end }} {{ end }}
<script>
window.redirectToJellyfin = {{ .redirectToJellyfin }};
</script>
</head> </head>
<body class="max-w-full overflow-x-hidden section"> <body class="max-w-full overflow-x-hidden section">
<div id="modal-success" class="modal"> <div id="modal-success" class="modal">

View File

@ -10,7 +10,8 @@ interface formWindow extends Window {
telegramModal: Modal; telegramModal: Modal;
discordModal: Modal; discordModal: Modal;
matrixModal: Modal; matrixModal: Modal;
confirmationModal: Modal confirmationModal: Modal;
redirectToJellyfin: boolean;
code: string; code: string;
messages: { [key: string]: string }; messages: { [key: string]: string };
confirmation: boolean; confirmation: boolean;
@ -412,7 +413,12 @@ const create = (event: SubmitEvent) => {
if (!vals[type]) { valid = false; } if (!vals[type]) { valid = false; }
} }
if (req.status == 200 && valid) { if (req.status == 200 && valid) {
if (window.redirectToJellyfin == true) {
const url = ((document.getElementById("modal-success") as HTMLDivElement).querySelector("a.submit") as HTMLAnchorElement).href;
window.location.href = url;
} else {
window.successModal.show(); window.successModal.show();
}
} else { } else {
submitSpan.classList.add("~critical"); submitSpan.classList.add("~critical");
submitSpan.classList.remove("~urge"); submitSpan.classList.remove("~urge");

View File

@ -170,6 +170,7 @@ func (app *appContext) ResetPassword(gc *gin.Context) {
data["helpMessage"] = app.config.Section("ui").Key("help_message").String() data["helpMessage"] = app.config.Section("ui").Key("help_message").String()
data["successMessage"] = app.config.Section("ui").Key("success_message").String() data["successMessage"] = app.config.Section("ui").Key("success_message").String()
data["jfLink"] = app.config.Section("ui").Key("redirect_url").String() data["jfLink"] = app.config.Section("ui").Key("redirect_url").String()
data["redirectToJellyfin"] = app.config.Section("ui").Key("auto_redirect").MustBool(false)
data["validate"] = app.config.Section("password_validation").Key("enabled").MustBool(false) data["validate"] = app.config.Section("password_validation").Key("enabled").MustBool(false)
data["requirements"] = app.validator.getCriteria() data["requirements"] = app.validator.getCriteria()
data["strings"] = app.storage.lang.PasswordReset[lang].Strings data["strings"] = app.storage.lang.PasswordReset[lang].Strings
@ -437,13 +438,18 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
fail() fail()
return return
} }
jfLink := app.config.Section("ui").Key("redirect_url").String()
if app.config.Section("ui").Key("auto_redirect").MustBool(false) {
gc.Redirect(301, jfLink)
} else {
gcHTML(gc, http.StatusOK, "create-success.html", gin.H{ gcHTML(gc, http.StatusOK, "create-success.html", gin.H{
"cssClass": app.cssClass, "cssClass": app.cssClass,
"strings": app.storage.lang.Form[lang].Strings, "strings": app.storage.lang.Form[lang].Strings,
"successMessage": app.config.Section("ui").Key("success_message").String(), "successMessage": app.config.Section("ui").Key("success_message").String(),
"contactMessage": app.config.Section("ui").Key("contact_message").String(), "contactMessage": app.config.Section("ui").Key("contact_message").String(),
"jfLink": app.config.Section("ui").Key("redirect_url").String(), "jfLink": jfLink,
}) })
}
inv, ok := app.storage.invites[code] inv, ok := app.storage.invites[code]
if ok { if ok {
l := len(inv.Keys) l := len(inv.Keys)
@ -468,6 +474,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
"helpMessage": app.config.Section("ui").Key("help_message").String(), "helpMessage": app.config.Section("ui").Key("help_message").String(),
"successMessage": app.config.Section("ui").Key("success_message").String(), "successMessage": app.config.Section("ui").Key("success_message").String(),
"jfLink": app.config.Section("ui").Key("redirect_url").String(), "jfLink": app.config.Section("ui").Key("redirect_url").String(),
"redirectToJellyfin": app.config.Section("ui").Key("auto_redirect").MustBool(false),
"validate": app.config.Section("password_validation").Key("enabled").MustBool(false), "validate": app.config.Section("password_validation").Key("enabled").MustBool(false),
"requirements": app.validator.getCriteria(), "requirements": app.validator.getCriteria(),
"email": email, "email": email,