2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-07 21:38:23 +00:00
|
|
|
"bufio"
|
|
|
|
"bytes"
|
2023-06-15 16:11:27 +00:00
|
|
|
"encoding/json"
|
2024-08-01 19:17:05 +00:00
|
|
|
"fmt"
|
2021-05-21 20:35:25 +00:00
|
|
|
"html/template"
|
2023-06-15 16:11:27 +00:00
|
|
|
"io"
|
2021-03-01 00:32:09 +00:00
|
|
|
"io/fs"
|
2020-07-29 21:11:28 +00:00
|
|
|
"net/http"
|
2023-06-15 16:11:27 +00:00
|
|
|
"net/url"
|
2023-06-23 12:43:48 +00:00
|
|
|
"path/filepath"
|
2020-10-22 16:50:40 +00:00
|
|
|
"strings"
|
2021-01-30 19:19:12 +00:00
|
|
|
"time"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-07-27 09:08:01 +00:00
|
|
|
"github.com/golang-jwt/jwt"
|
2023-06-20 20:43:25 +00:00
|
|
|
"github.com/gomarkdown/markdown"
|
2024-08-06 19:34:28 +00:00
|
|
|
"github.com/hrfee/jfa-go/common"
|
2024-08-01 19:17:05 +00:00
|
|
|
lm "github.com/hrfee/jfa-go/logmessages"
|
2021-10-13 14:19:52 +00:00
|
|
|
"github.com/hrfee/mediabrowser"
|
2023-10-19 17:56:35 +00:00
|
|
|
"github.com/lithammer/shortuuid/v3"
|
2022-01-10 01:55:48 +00:00
|
|
|
"github.com/steambap/captcha"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2022-01-08 16:42:36 +00:00
|
|
|
var cssVersion string
|
|
|
|
var css = []string{cssVersion + "bundle.css", "remixicon.css"}
|
2021-02-05 13:10:47 +00:00
|
|
|
var cssHeader string
|
|
|
|
|
|
|
|
func (app *appContext) loadCSSHeader() string {
|
2021-01-15 18:57:12 +00:00
|
|
|
l := len(css)
|
|
|
|
h := ""
|
|
|
|
for i, f := range css {
|
2021-02-05 13:10:47 +00:00
|
|
|
h += "<" + app.URLBase + "/css/" + f + ">; rel=preload; as=style"
|
2021-01-15 18:57:12 +00:00
|
|
|
if l > 1 && i != (l-1) {
|
|
|
|
h += ", "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return h
|
2021-02-05 13:10:47 +00:00
|
|
|
}
|
2021-01-15 18:57:12 +00:00
|
|
|
|
2021-02-11 23:06:51 +00:00
|
|
|
func (app *appContext) getURLBase(gc *gin.Context) string {
|
|
|
|
if strings.HasPrefix(gc.Request.URL.String(), app.URLBase) {
|
2023-10-22 14:02:03 +00:00
|
|
|
// Hack to fix the common URL base /accounts
|
|
|
|
if app.URLBase == "/accounts" && strings.HasPrefix(gc.Request.URL.String(), "/accounts/user/") {
|
|
|
|
return ""
|
|
|
|
}
|
2021-02-11 23:06:51 +00:00
|
|
|
return app.URLBase
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
func gcHTML(gc *gin.Context, code int, file string, templ gin.H) {
|
|
|
|
gc.Header("Cache-Control", "no-cache")
|
|
|
|
gc.HTML(code, file, templ)
|
|
|
|
}
|
|
|
|
|
2023-06-16 13:43:37 +00:00
|
|
|
func (app *appContext) pushResources(gc *gin.Context, page Page) {
|
|
|
|
var toPush []string
|
|
|
|
switch page {
|
|
|
|
case AdminPage:
|
|
|
|
toPush = []string{"/js/admin.js", "/js/theme.js", "/js/lang.js", "/js/modal.js", "/js/tabs.js", "/js/invites.js", "/js/accounts.js", "/js/settings.js", "/js/profiles.js", "/js/common.js"}
|
|
|
|
break
|
|
|
|
case UserPage:
|
|
|
|
toPush = []string{"/js/user.js", "/js/theme.js", "/js/lang.js", "/js/modal.js", "/js/common.js"}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
toPush = []string{}
|
|
|
|
}
|
2021-01-15 18:57:12 +00:00
|
|
|
if pusher := gc.Writer.Pusher(); pusher != nil {
|
2023-06-16 13:43:37 +00:00
|
|
|
for _, f := range toPush {
|
|
|
|
if err := pusher.Push(app.URLBase+f, nil); err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.FailedServerPush, err)
|
2021-01-15 18:57:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gc.Header("Link", cssHeader)
|
|
|
|
}
|
|
|
|
|
2021-05-03 17:35:27 +00:00
|
|
|
type Page int
|
|
|
|
|
2021-04-08 15:03:46 +00:00
|
|
|
const (
|
2021-05-03 17:35:27 +00:00
|
|
|
AdminPage Page = iota + 1
|
2021-04-08 15:03:46 +00:00
|
|
|
FormPage
|
|
|
|
PWRPage
|
2023-06-16 13:43:37 +00:00
|
|
|
UserPage
|
|
|
|
OtherPage
|
2021-04-08 15:03:46 +00:00
|
|
|
)
|
|
|
|
|
2021-05-03 17:35:27 +00:00
|
|
|
func (app *appContext) getLang(gc *gin.Context, page Page, chosen string) string {
|
2021-01-12 00:11:40 +00:00
|
|
|
lang := gc.Query("lang")
|
2021-04-08 15:03:46 +00:00
|
|
|
cookie, err := gc.Cookie("lang")
|
|
|
|
if lang != "" {
|
|
|
|
switch page {
|
|
|
|
case AdminPage:
|
|
|
|
if _, ok := app.storage.lang.Admin[lang]; ok {
|
|
|
|
gc.SetCookie("lang", lang, (365 * 3600), "/", gc.Request.URL.Hostname(), true, true)
|
|
|
|
return lang
|
|
|
|
}
|
2023-06-16 13:43:37 +00:00
|
|
|
case FormPage, UserPage:
|
|
|
|
if _, ok := app.storage.lang.User[lang]; ok {
|
2021-04-08 15:03:46 +00:00
|
|
|
gc.SetCookie("lang", lang, (365 * 3600), "/", gc.Request.URL.Hostname(), true, true)
|
|
|
|
return lang
|
|
|
|
}
|
|
|
|
case PWRPage:
|
|
|
|
if _, ok := app.storage.lang.PasswordReset[lang]; ok {
|
|
|
|
gc.SetCookie("lang", lang, (365 * 3600), "/", gc.Request.URL.Hostname(), true, true)
|
|
|
|
return lang
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cookie != "" && err == nil {
|
|
|
|
switch page {
|
|
|
|
case AdminPage:
|
|
|
|
if _, ok := app.storage.lang.Admin[cookie]; ok {
|
|
|
|
return cookie
|
|
|
|
}
|
2023-06-16 13:43:37 +00:00
|
|
|
case FormPage, UserPage:
|
|
|
|
if _, ok := app.storage.lang.User[cookie]; ok {
|
2021-04-08 15:03:46 +00:00
|
|
|
return cookie
|
|
|
|
}
|
|
|
|
case PWRPage:
|
|
|
|
if _, ok := app.storage.lang.PasswordReset[cookie]; ok {
|
|
|
|
return cookie
|
|
|
|
}
|
|
|
|
}
|
2021-01-12 00:11:40 +00:00
|
|
|
}
|
2021-04-08 15:03:46 +00:00
|
|
|
return chosen
|
2021-02-02 18:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *appContext) AdminPage(gc *gin.Context) {
|
2023-06-16 13:43:37 +00:00
|
|
|
app.pushResources(gc, AdminPage)
|
2021-04-08 15:03:46 +00:00
|
|
|
lang := app.getLang(gc, AdminPage, app.storage.lang.chosenAdminLang)
|
2020-08-16 12:36:54 +00:00
|
|
|
emailEnabled, _ := app.config.Section("invite_emails").Key("enabled").Bool()
|
|
|
|
notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()
|
2020-09-05 16:32:49 +00:00
|
|
|
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
2024-07-30 15:36:59 +00:00
|
|
|
jellyseerrEnabled := app.config.Section("jellyseerr").Key("enabled").MustBool(false)
|
2022-01-09 19:29:17 +00:00
|
|
|
jfAdminOnly := app.config.Section("ui").Key("admin_only").MustBool(true)
|
|
|
|
jfAllowAll := app.config.Section("ui").Key("allow_all").MustBool(false)
|
2021-03-01 00:32:09 +00:00
|
|
|
var license string
|
|
|
|
l, err := fs.ReadFile(localFS, "LICENSE")
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.FailedReading, "LICENSE", err)
|
2021-03-01 00:32:09 +00:00
|
|
|
license = ""
|
|
|
|
}
|
|
|
|
license = string(l)
|
2023-06-23 12:43:48 +00:00
|
|
|
fontLicense, err := fs.ReadFile(localFS, filepath.Join("web", "fonts", "OFL.txt"))
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.FailedReading, "fontLicense", err)
|
2023-06-23 12:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
license += "---Hanken Grotesk---\n\n"
|
|
|
|
license += string(fontLicense)
|
|
|
|
|
2023-06-23 13:41:21 +00:00
|
|
|
if builtBy == "" {
|
|
|
|
builtBy = "???"
|
|
|
|
}
|
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "admin.html", gin.H{
|
2024-07-30 15:36:59 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": "",
|
|
|
|
"emailEnabled": emailEnabled,
|
|
|
|
"telegramEnabled": telegramEnabled,
|
|
|
|
"discordEnabled": discordEnabled,
|
|
|
|
"matrixEnabled": matrixEnabled,
|
|
|
|
"ombiEnabled": ombiEnabled,
|
|
|
|
"jellyseerrEnabled": jellyseerrEnabled,
|
|
|
|
"linkResetEnabled": app.config.Section("password_resets").Key("link_reset").MustBool(false),
|
|
|
|
"notifications": notificationsEnabled,
|
|
|
|
"version": version,
|
|
|
|
"commit": commit,
|
|
|
|
"buildTime": buildTime,
|
|
|
|
"builtBy": builtBy,
|
2024-08-11 16:55:12 +00:00
|
|
|
"buildTags": buildTags,
|
2024-07-30 15:36:59 +00:00
|
|
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
|
|
|
"strings": app.storage.lang.Admin[lang].Strings,
|
|
|
|
"quantityStrings": app.storage.lang.Admin[lang].QuantityStrings,
|
|
|
|
"language": app.storage.lang.Admin[lang].JSON,
|
|
|
|
"langName": lang,
|
|
|
|
"license": license,
|
|
|
|
"jellyfinLogin": app.jellyfinLogin,
|
|
|
|
"jfAdminOnly": jfAdminOnly,
|
|
|
|
"jfAllowAll": jfAllowAll,
|
|
|
|
"userPageEnabled": app.config.Section("user_page").Key("enabled").MustBool(false),
|
|
|
|
"showUserPageLink": app.config.Section("user_page").Key("show_link").MustBool(true),
|
|
|
|
"referralsEnabled": app.config.Section("user_page").Key("enabled").MustBool(false) && app.config.Section("user_page").Key("referrals").MustBool(false),
|
|
|
|
"loginAppearance": app.config.Section("ui").Key("login_appearance").MustString("clear"),
|
2020-07-29 21:11:28 +00:00
|
|
|
})
|
|
|
|
}
|
2020-07-31 11:48:37 +00:00
|
|
|
|
2023-06-16 13:43:37 +00:00
|
|
|
func (app *appContext) MyUserPage(gc *gin.Context) {
|
|
|
|
app.pushResources(gc, UserPage)
|
|
|
|
lang := app.getLang(gc, UserPage, app.storage.lang.chosenUserLang)
|
|
|
|
emailEnabled, _ := app.config.Section("invite_emails").Key("enabled").Bool()
|
|
|
|
notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()
|
|
|
|
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
2024-07-30 15:36:59 +00:00
|
|
|
jellyseerrEnabled := app.config.Section("jellyseerr").Key("enabled").MustBool(false)
|
2023-06-18 20:38:12 +00:00
|
|
|
data := gin.H{
|
2023-06-17 11:48:28 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
"emailEnabled": emailEnabled,
|
2023-06-18 20:38:12 +00:00
|
|
|
"emailRequired": app.config.Section("email").Key("required").MustBool(false),
|
2023-06-17 11:48:28 +00:00
|
|
|
"telegramEnabled": telegramEnabled,
|
|
|
|
"discordEnabled": discordEnabled,
|
|
|
|
"matrixEnabled": matrixEnabled,
|
|
|
|
"ombiEnabled": ombiEnabled,
|
2024-07-30 15:36:59 +00:00
|
|
|
"jellyseerrEnabled": jellyseerrEnabled,
|
2023-06-22 11:04:40 +00:00
|
|
|
"pwrEnabled": app.config.Section("password_resets").Key("enabled").MustBool(false),
|
2023-06-17 11:48:28 +00:00
|
|
|
"linkResetEnabled": app.config.Section("password_resets").Key("link_reset").MustBool(false),
|
|
|
|
"notifications": notificationsEnabled,
|
|
|
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
|
|
|
"strings": app.storage.lang.User[lang].Strings,
|
2023-06-22 17:31:16 +00:00
|
|
|
"validationStrings": app.storage.lang.User[lang].validationStringsJSON,
|
2023-06-17 11:48:28 +00:00
|
|
|
"language": app.storage.lang.User[lang].JSON,
|
|
|
|
"langName": lang,
|
2023-06-22 11:04:40 +00:00
|
|
|
"jfLink": app.config.Section("ui").Key("redirect_url").String(),
|
2023-06-22 17:31:16 +00:00
|
|
|
"requirements": app.validator.getCriteria(),
|
2023-09-07 15:24:40 +00:00
|
|
|
"referralsEnabled": app.config.Section("user_page").Key("enabled").MustBool(false) && app.config.Section("user_page").Key("referrals").MustBool(false),
|
2023-06-18 20:38:12 +00:00
|
|
|
}
|
|
|
|
if telegramEnabled {
|
2023-06-19 21:11:35 +00:00
|
|
|
data["telegramUsername"] = app.telegram.username
|
2023-06-18 20:38:12 +00:00
|
|
|
data["telegramURL"] = app.telegram.link
|
|
|
|
data["telegramRequired"] = app.config.Section("telegram").Key("required").MustBool(false)
|
|
|
|
}
|
|
|
|
if matrixEnabled {
|
|
|
|
data["matrixRequired"] = app.config.Section("matrix").Key("required").MustBool(false)
|
|
|
|
data["matrixUser"] = app.matrix.userID
|
|
|
|
}
|
|
|
|
if discordEnabled {
|
|
|
|
data["discordUsername"] = app.discord.username
|
|
|
|
data["discordRequired"] = app.config.Section("discord").Key("required").MustBool(false)
|
|
|
|
data["discordSendPINMessage"] = template.HTML(app.storage.lang.User[lang].Strings.template("sendPINDiscord", tmpl{
|
|
|
|
"command": `<span class="text-black dark:text-white font-mono">/` + app.config.Section("discord").Key("start_command").MustString("start") + `</span>`,
|
|
|
|
"server_channel": app.discord.serverChannelName,
|
|
|
|
}))
|
|
|
|
data["discordServerName"] = app.discord.serverName
|
2024-08-03 20:23:59 +00:00
|
|
|
data["discordInviteLink"] = app.discord.InviteChannel.Name != ""
|
2023-06-18 20:38:12 +00:00
|
|
|
}
|
2023-12-20 18:18:39 +00:00
|
|
|
if data["linkResetEnabled"].(bool) {
|
|
|
|
data["resetPasswordUsername"] = app.config.Section("user_page").Key("allow_pwr_username").MustBool(true)
|
|
|
|
data["resetPasswordEmail"] = app.config.Section("user_page").Key("allow_pwr_email").MustBool(true)
|
|
|
|
data["resetPasswordContactMethod"] = app.config.Section("user_page").Key("allow_pwr_contact_method").MustBool(true)
|
|
|
|
}
|
2023-06-20 20:43:25 +00:00
|
|
|
|
2023-06-25 18:40:54 +00:00
|
|
|
pageMessagesExist := map[string]bool{}
|
|
|
|
pageMessages := map[string]CustomContent{}
|
|
|
|
pageMessages["Login"], pageMessagesExist["Login"] = app.storage.GetCustomContentKey("UserLogin")
|
|
|
|
pageMessages["Page"], pageMessagesExist["Page"] = app.storage.GetCustomContentKey("UserPage")
|
2023-06-20 20:43:25 +00:00
|
|
|
|
|
|
|
for name, msg := range pageMessages {
|
2023-06-25 18:40:54 +00:00
|
|
|
if !pageMessagesExist[name] {
|
2023-06-20 20:43:25 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
data[name+"MessageEnabled"] = msg.Enabled
|
|
|
|
if !msg.Enabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// We don't template here, since the username is only known after login.
|
|
|
|
data[name+"MessageContent"] = template.HTML(markdown.ToHTML([]byte(msg.Content), nil, markdownRenderer))
|
|
|
|
}
|
|
|
|
|
2023-06-18 20:38:12 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "user.html", data)
|
2023-06-16 13:43:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 21:41:28 +00:00
|
|
|
func (app *appContext) ResetPassword(gc *gin.Context) {
|
2021-05-29 18:24:00 +00:00
|
|
|
isBot := strings.Contains(gc.Request.Header.Get("User-Agent"), "Bot")
|
2021-06-07 12:46:46 +00:00
|
|
|
setPassword := app.config.Section("password_resets").Key("set_password").MustBool(false)
|
2021-03-30 21:41:28 +00:00
|
|
|
pin := gc.Query("pin")
|
|
|
|
if pin == "" {
|
|
|
|
app.NoRouteHandler(gc)
|
|
|
|
return
|
|
|
|
}
|
2023-06-16 13:43:37 +00:00
|
|
|
app.pushResources(gc, PWRPage)
|
2021-04-08 15:03:46 +00:00
|
|
|
lang := app.getLang(gc, PWRPage, app.storage.lang.chosenPWRLang)
|
2021-03-30 21:41:28 +00:00
|
|
|
data := gin.H{
|
2024-07-28 18:32:48 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"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),
|
2024-07-30 15:36:59 +00:00
|
|
|
"jellyseerrEnabled": app.config.Section("jellyseerr").Key("enabled").MustBool(false),
|
2024-07-28 18:32:48 +00:00
|
|
|
"customSuccessCard": false,
|
2021-03-30 21:41:28 +00:00
|
|
|
}
|
2021-10-13 14:19:52 +00:00
|
|
|
pwr, isInternal := app.internalPWRs[pin]
|
2023-12-20 19:04:40 +00:00
|
|
|
// if isInternal && setPassword {
|
|
|
|
if setPassword {
|
2021-06-07 12:46:46 +00:00
|
|
|
data["helpMessage"] = app.config.Section("ui").Key("help_message").String()
|
|
|
|
data["successMessage"] = app.config.Section("ui").Key("success_message").String()
|
2021-12-20 20:44:08 +00:00
|
|
|
data["jfLink"] = app.config.Section("ui").Key("redirect_url").String()
|
2023-02-02 10:34:22 +00:00
|
|
|
data["redirectToJellyfin"] = app.config.Section("ui").Key("auto_redirect").MustBool(false)
|
2021-06-07 12:46:46 +00:00
|
|
|
data["validate"] = app.config.Section("password_validation").Key("enabled").MustBool(false)
|
|
|
|
data["requirements"] = app.validator.getCriteria()
|
|
|
|
data["strings"] = app.storage.lang.PasswordReset[lang].Strings
|
2023-06-16 13:43:37 +00:00
|
|
|
data["validationStrings"] = app.storage.lang.User[lang].validationStringsJSON
|
|
|
|
data["notifications"] = app.storage.lang.User[lang].notificationsJSON
|
2021-06-07 12:46:46 +00:00
|
|
|
data["langName"] = lang
|
|
|
|
data["passwordReset"] = true
|
|
|
|
data["telegramEnabled"] = false
|
|
|
|
data["discordEnabled"] = false
|
|
|
|
data["matrixEnabled"] = false
|
2023-12-23 18:20:09 +00:00
|
|
|
data["captcha"] = app.config.Section("captcha").Key("enabled").MustBool(false)
|
|
|
|
data["reCAPTCHA"] = app.config.Section("captcha").Key("recaptcha").MustBool(false)
|
|
|
|
data["reCAPTCHASiteKey"] = app.config.Section("captcha").Key("recaptcha_site_key").MustString("")
|
2023-12-23 19:56:21 +00:00
|
|
|
data["pwrPIN"] = pin
|
2021-06-07 12:46:46 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "form-loader.html", data)
|
|
|
|
return
|
|
|
|
}
|
2021-05-29 18:24:00 +00:00
|
|
|
defer gcHTML(gc, http.StatusOK, "password-reset.html", data)
|
|
|
|
// If it's a bot, pretend to be a success so the preview is nice.
|
|
|
|
if isBot {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Println(lm.IgnoreBotPWR)
|
2021-03-30 21:41:28 +00:00
|
|
|
data["success"] = true
|
2021-05-29 18:24:00 +00:00
|
|
|
data["pin"] = "NO-BO-TS"
|
2021-10-13 14:04:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// if reset, ok := app.internalPWRs[pin]; ok {
|
|
|
|
// status, err := app.jf.ResetPasswordAdmin(reset.ID)
|
|
|
|
// if !(status == 200 || status == 204) || err != nil {
|
|
|
|
// app.err.Printf("Password Reset failed (%d): %v", status, err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// status, err = app.jf.SetPassword(reset.ID, "", pin)
|
|
|
|
// if !(status == 200 || status == 204) || err != nil {
|
|
|
|
// app.err.Printf("Password Reset failed (%d): %v", status, err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// data["success"] = true
|
|
|
|
// data["pin"] = pin
|
|
|
|
// }
|
2021-10-13 14:19:52 +00:00
|
|
|
var resp mediabrowser.PasswordResetResponse
|
|
|
|
var err error
|
|
|
|
var username string
|
2023-12-20 19:04:40 +00:00
|
|
|
if !isInternal && !setPassword {
|
2024-08-06 13:48:31 +00:00
|
|
|
resp, err = app.jf.ResetPassword(pin)
|
2021-10-13 14:19:52 +00:00
|
|
|
} else if time.Now().After(pwr.Expiry) {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.FailedChangePassword, lm.Jellyfin, "?", fmt.Sprintf(lm.ExpiredPIN, pin))
|
2021-10-13 14:19:52 +00:00
|
|
|
app.NoRouteHandler(gc)
|
|
|
|
return
|
|
|
|
} else {
|
2024-08-06 13:48:31 +00:00
|
|
|
err = app.jf.ResetPasswordAdmin(pwr.ID)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedChangePassword, lm.Jellyfin, "?", err)
|
2021-10-13 14:19:52 +00:00
|
|
|
} else {
|
2024-08-06 13:48:31 +00:00
|
|
|
err = app.jf.SetPassword(pwr.ID, "", pin)
|
2021-10-13 14:19:52 +00:00
|
|
|
}
|
|
|
|
username = pwr.Username
|
|
|
|
}
|
2023-10-19 17:56:35 +00:00
|
|
|
|
2024-08-06 13:48:31 +00:00
|
|
|
if err == nil && (isInternal || resp.Success) {
|
2021-10-13 14:04:22 +00:00
|
|
|
data["success"] = true
|
|
|
|
data["pin"] = pin
|
2021-10-13 14:19:52 +00:00
|
|
|
if !isInternal {
|
|
|
|
username = resp.UsersReset[0]
|
|
|
|
}
|
2021-03-30 21:41:28 +00:00
|
|
|
} else {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedChangePassword, lm.Jellyfin, "?", err)
|
2021-10-13 14:04:22 +00:00
|
|
|
}
|
2023-10-19 17:56:35 +00:00
|
|
|
|
|
|
|
// Only log PWRs we know the user for.
|
|
|
|
if username != "" {
|
2024-08-06 13:48:31 +00:00
|
|
|
jfUser, err := app.jf.UserByName(username, false)
|
|
|
|
if err == nil {
|
2023-10-19 17:56:35 +00:00
|
|
|
app.storage.SetActivityKey(shortuuid.New(), Activity{
|
|
|
|
Type: ActivityResetPassword,
|
|
|
|
UserID: jfUser.ID,
|
|
|
|
SourceType: ActivityUser,
|
|
|
|
Source: jfUser.ID,
|
|
|
|
Time: time.Now(),
|
2023-12-23 21:47:41 +00:00
|
|
|
}, gc, true)
|
2023-10-19 17:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-13 14:04:22 +00:00
|
|
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
2024-08-06 13:48:31 +00:00
|
|
|
jfUser, err := app.jf.UserByName(username, false)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedGetUser, username, lm.Jellyfin, err)
|
2021-10-13 14:04:22 +00:00
|
|
|
return
|
2021-05-02 12:23:59 +00:00
|
|
|
}
|
2024-08-06 13:48:31 +00:00
|
|
|
ombiUser, err := app.getOmbiUser(jfUser.ID)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedGetUser, username, lm.Ombi, err)
|
2021-10-13 14:04:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ombiUser["password"] = pin
|
2024-08-06 13:48:31 +00:00
|
|
|
err = app.ombi.ModifyUser(ombiUser)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedChangePassword, lm.Ombi, ombiUser["userName"], err)
|
2021-10-13 14:04:22 +00:00
|
|
|
return
|
2021-05-02 12:23:59 +00:00
|
|
|
}
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.ChangePassword, lm.Ombi, ombiUser["userName"])
|
2021-05-02 12:23:59 +00:00
|
|
|
}
|
2021-03-30 21:41:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 01:55:48 +00:00
|
|
|
// @Summary returns the captcha image corresponding to the given ID.
|
|
|
|
// @Param code path string true "invite code"
|
|
|
|
// @Param captchaID path string true "captcha ID"
|
|
|
|
// @Tags Other
|
|
|
|
// @Router /captcha/img/{code}/{captchaID} [get]
|
|
|
|
func (app *appContext) GetCaptcha(gc *gin.Context) {
|
|
|
|
code := gc.Param("invCode")
|
2023-12-23 19:56:21 +00:00
|
|
|
isPWR := gc.Query("pwr") == "true"
|
2022-01-10 01:55:48 +00:00
|
|
|
captchaID := gc.Param("captchaID")
|
2023-12-23 19:56:21 +00:00
|
|
|
var inv Invite
|
2023-09-07 21:38:23 +00:00
|
|
|
var capt Captcha
|
2023-12-23 19:56:21 +00:00
|
|
|
ok := true
|
|
|
|
if !isPWR {
|
|
|
|
inv, ok = app.storage.GetInvitesKey(code)
|
|
|
|
if !ok {
|
|
|
|
gcHTML(gc, 404, "invalidCode.html", gin.H{
|
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if inv.Captchas != nil {
|
|
|
|
capt, ok = inv.Captchas[captchaID]
|
|
|
|
} else {
|
|
|
|
ok = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
capt, ok = app.pwrCaptchas[code]
|
2022-01-10 01:55:48 +00:00
|
|
|
}
|
2023-09-07 21:38:23 +00:00
|
|
|
if !ok {
|
2022-01-10 01:55:48 +00:00
|
|
|
respondBool(400, false, gc)
|
|
|
|
return
|
|
|
|
}
|
2023-09-07 21:38:23 +00:00
|
|
|
gc.Data(200, "image/png", capt.Image)
|
2022-01-10 01:55:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary Generates a new captcha and returns it's ID. This can then be included in a request to /captcha/img/{id} to get an image.
|
|
|
|
// @Produce json
|
|
|
|
// @Param code path string true "invite code"
|
|
|
|
// @Success 200 {object} genCaptchaDTO
|
|
|
|
// @Router /captcha/gen/{code} [get]
|
|
|
|
// @Security Bearer
|
|
|
|
// @tags Users
|
|
|
|
func (app *appContext) GenCaptcha(gc *gin.Context) {
|
|
|
|
code := gc.Param("invCode")
|
2023-12-23 19:56:21 +00:00
|
|
|
isPWR := gc.Query("pwr") == "true"
|
|
|
|
var inv Invite
|
|
|
|
ok := true
|
|
|
|
if !isPWR {
|
|
|
|
inv, ok = app.storage.GetInvitesKey(code)
|
|
|
|
}
|
|
|
|
|
2022-01-10 01:55:48 +00:00
|
|
|
if !ok {
|
|
|
|
gcHTML(gc, 404, "invalidCode.html", gin.H{
|
2023-06-21 20:22:05 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
2022-01-10 01:55:48 +00:00
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
capt, err := captcha.New(300, 100)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedGenerateCaptcha, err)
|
2022-01-10 01:55:48 +00:00
|
|
|
respondBool(500, false, gc)
|
|
|
|
return
|
|
|
|
}
|
2023-12-23 19:56:21 +00:00
|
|
|
if !isPWR && inv.Captchas == nil {
|
2023-09-07 21:38:23 +00:00
|
|
|
inv.Captchas = map[string]Captcha{}
|
2022-01-10 01:55:48 +00:00
|
|
|
}
|
|
|
|
captchaID := genAuthToken()
|
2023-09-07 21:38:23 +00:00
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := capt.WriteImage(bufio.NewWriter(&buf)); err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedGenerateCaptcha, err)
|
2023-09-07 21:38:23 +00:00
|
|
|
respondBool(500, false, gc)
|
|
|
|
return
|
|
|
|
}
|
2023-12-23 19:56:21 +00:00
|
|
|
if isPWR {
|
|
|
|
if app.pwrCaptchas == nil {
|
|
|
|
app.pwrCaptchas = map[string]Captcha{}
|
|
|
|
}
|
|
|
|
app.pwrCaptchas[code] = Captcha{
|
|
|
|
Answer: capt.Text,
|
|
|
|
Image: buf.Bytes(),
|
|
|
|
Generated: time.Now(),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inv.Captchas[captchaID] = Captcha{
|
|
|
|
Answer: capt.Text,
|
|
|
|
Image: buf.Bytes(),
|
|
|
|
Generated: time.Now(),
|
|
|
|
}
|
|
|
|
app.storage.SetInvitesKey(code, inv)
|
2023-09-07 21:38:23 +00:00
|
|
|
}
|
2022-01-10 01:55:48 +00:00
|
|
|
gc.JSON(200, genCaptchaDTO{captchaID})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-23 19:56:21 +00:00
|
|
|
func (app *appContext) verifyCaptcha(code, id, text string, isPWR bool) bool {
|
2023-06-15 16:11:27 +00:00
|
|
|
reCAPTCHA := app.config.Section("captcha").Key("recaptcha").MustBool(false)
|
|
|
|
if !reCAPTCHA {
|
|
|
|
// internal CAPTCHA
|
2023-12-23 19:56:21 +00:00
|
|
|
var c Captcha
|
|
|
|
ok := true
|
|
|
|
if !isPWR {
|
|
|
|
inv, ok := app.storage.GetInvitesKey(code)
|
2024-08-01 19:17:05 +00:00
|
|
|
if !ok {
|
|
|
|
app.debug.Printf(lm.InvalidInviteCode, code)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !isPWR && inv.Captchas == nil {
|
|
|
|
app.debug.Printf(lm.CaptchaNotFound, id, code)
|
2023-12-23 19:56:21 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
c, ok = inv.Captchas[id]
|
|
|
|
} else {
|
|
|
|
c, ok = app.pwrCaptchas[code]
|
2023-06-15 16:11:27 +00:00
|
|
|
}
|
|
|
|
if !ok {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.debug.Printf(lm.CaptchaNotFound, id, code)
|
2023-06-15 16:11:27 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-09-07 21:38:23 +00:00
|
|
|
return strings.ToLower(c.Answer) == strings.ToLower(text)
|
2023-06-15 16:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// reCAPTCHA
|
|
|
|
|
|
|
|
msg := ReCaptchaRequestDTO{
|
|
|
|
Secret: app.config.Section("captcha").Key("recaptcha_secret_key").MustString(""),
|
|
|
|
Response: text,
|
|
|
|
}
|
|
|
|
// Why doesn't this endpoint accept JSON???
|
|
|
|
urlencode := url.Values{}
|
|
|
|
urlencode.Set("secret", msg.Secret)
|
|
|
|
urlencode.Set("response", msg.Response)
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("POST", "https://www.google.com/recaptcha/api/siteverify", strings.NewReader(urlencode.Encode()))
|
|
|
|
|
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
2024-08-06 19:34:28 +00:00
|
|
|
err = common.GenericErr(resp.StatusCode, err)
|
2024-08-01 19:17:05 +00:00
|
|
|
if err != nil {
|
|
|
|
app.err.Printf(lm.FailedVerifyReCAPTCHA, err)
|
2022-01-10 01:55:48 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-06-15 16:11:27 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
var data ReCaptchaResponseDTO
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
err = json.Unmarshal(body, &data)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedVerifyReCAPTCHA, err)
|
2023-06-15 16:11:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
hostname := app.config.Section("captcha").Key("recaptcha_hostname").MustString("")
|
|
|
|
if strings.ToLower(data.Hostname) != strings.ToLower(hostname) && data.Hostname != "" {
|
2024-08-01 19:17:05 +00:00
|
|
|
err = fmt.Errorf(lm.InvalidHostname, hostname, data.Hostname)
|
|
|
|
app.err.Printf(lm.FailedVerifyReCAPTCHA, err)
|
2022-01-10 01:55:48 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-06-15 16:11:27 +00:00
|
|
|
|
|
|
|
if len(data.ErrorCodes) > 0 {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.AdditionalErrors, lm.ReCAPTCHA, data.ErrorCodes)
|
2023-06-15 16:11:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.Success
|
2022-01-10 01:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Summary returns 204 if the given Captcha contents is correct for the corresponding captcha ID and invite code.
|
|
|
|
// @Param code path string true "invite code"
|
|
|
|
// @Param captchaID path string true "captcha ID"
|
|
|
|
// @Param text path string true "Captcha text"
|
|
|
|
// @Success 204
|
|
|
|
// @Tags Other
|
|
|
|
// @Router /captcha/verify/{code}/{captchaID}/{text} [get]
|
|
|
|
func (app *appContext) VerifyCaptcha(gc *gin.Context) {
|
|
|
|
code := gc.Param("invCode")
|
2023-12-23 19:56:21 +00:00
|
|
|
isPWR := gc.Query("pwr") == "true"
|
2022-01-10 01:55:48 +00:00
|
|
|
captchaID := gc.Param("captchaID")
|
|
|
|
text := gc.Param("text")
|
2023-12-23 19:56:21 +00:00
|
|
|
var inv Invite
|
2023-09-07 21:38:23 +00:00
|
|
|
var capt Captcha
|
2023-12-23 19:56:21 +00:00
|
|
|
var ok bool
|
|
|
|
if !isPWR {
|
|
|
|
inv, ok = app.storage.GetInvitesKey(code)
|
|
|
|
if !ok {
|
|
|
|
gcHTML(gc, 404, "invalidCode.html", gin.H{
|
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if inv.Captchas != nil {
|
|
|
|
capt, ok = inv.Captchas[captchaID]
|
|
|
|
} else {
|
|
|
|
ok = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
capt, ok = app.pwrCaptchas[code]
|
2022-01-10 01:55:48 +00:00
|
|
|
}
|
2023-09-07 21:38:23 +00:00
|
|
|
if !ok {
|
2022-01-10 01:55:48 +00:00
|
|
|
respondBool(400, false, gc)
|
|
|
|
return
|
|
|
|
}
|
2023-09-07 21:38:23 +00:00
|
|
|
if strings.ToLower(capt.Answer) != strings.ToLower(text) {
|
2022-01-10 01:55:48 +00:00
|
|
|
respondBool(400, false, gc)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
respondBool(204, true, gc)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-03 20:23:59 +00:00
|
|
|
func (app *appContext) NewUserFromConfirmationKey(invite Invite, key string, lang string, gc *gin.Context) {
|
|
|
|
fail := func() {
|
|
|
|
gcHTML(gc, 404, "404.html", gin.H{
|
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
})
|
|
|
|
}
|
2024-10-11 15:38:19 +00:00
|
|
|
var req ConfirmationKey
|
2024-08-03 20:23:59 +00:00
|
|
|
if app.ConfirmationKeys == nil {
|
|
|
|
fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
invKeys, ok := app.ConfirmationKeys[invite.Code]
|
|
|
|
if !ok {
|
|
|
|
fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req, ok = invKeys[key]
|
|
|
|
if !ok {
|
|
|
|
fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
token, err := jwt.Parse(key, checkToken)
|
|
|
|
if err != nil {
|
|
|
|
fail()
|
|
|
|
app.debug.Printf(lm.FailedParseJWT, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
claims, ok := token.Claims.(jwt.MapClaims)
|
|
|
|
expiry := time.Unix(int64(claims["exp"].(float64)), 0)
|
|
|
|
if !(ok && token.Valid && claims["invite"].(string) == invite.Code && claims["type"].(string) == "confirmation" && expiry.After(time.Now())) {
|
|
|
|
fail()
|
|
|
|
app.debug.Printf(lm.InvalidJWT)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceType, source := invite.Source()
|
|
|
|
|
|
|
|
var profile *Profile = nil
|
|
|
|
if invite.Profile != "" {
|
|
|
|
p, ok := app.storage.GetProfileKey(invite.Profile)
|
|
|
|
if !ok {
|
|
|
|
app.debug.Printf(lm.FailedGetProfile+lm.FallbackToDefault, invite.Profile)
|
|
|
|
p = app.storage.GetDefaultProfile()
|
|
|
|
}
|
|
|
|
profile = &p
|
|
|
|
}
|
|
|
|
|
2024-10-11 15:38:19 +00:00
|
|
|
// FIXME: Email and contract method linking?????
|
|
|
|
|
2024-08-20 20:33:43 +00:00
|
|
|
nu /*wg*/, _ := app.NewUserPostVerification(NewUserParams{
|
2024-10-11 15:38:19 +00:00
|
|
|
Req: req.newUserDTO,
|
2024-08-03 20:23:59 +00:00
|
|
|
SourceType: sourceType,
|
|
|
|
Source: source,
|
|
|
|
ContextForIPLogging: gc,
|
|
|
|
Profile: profile,
|
|
|
|
})
|
|
|
|
if !nu.Success {
|
|
|
|
nu.Log()
|
|
|
|
}
|
|
|
|
if !nu.Created {
|
2024-08-24 13:21:15 +00:00
|
|
|
// respond(nu.Status, nu.Message, gc)
|
2024-08-03 20:23:59 +00:00
|
|
|
fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
app.checkInvite(req.Code, true, req.Username)
|
|
|
|
|
2024-10-11 15:38:19 +00:00
|
|
|
app.PostNewUserFromInvite(nu, req, profile, invite)
|
|
|
|
|
2024-08-03 20:23:59 +00:00
|
|
|
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{
|
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"strings": app.storage.lang.User[lang].Strings,
|
|
|
|
"successMessage": app.config.Section("ui").Key("success_message").String(),
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
"jfLink": jfLink,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
app.confirmationKeysLock.Lock()
|
|
|
|
// Re-fetch invKeys just incase an update occurred
|
|
|
|
invKeys, ok = app.ConfirmationKeys[invite.Code]
|
|
|
|
if !ok {
|
|
|
|
fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
delete(invKeys, key)
|
|
|
|
app.ConfirmationKeys[invite.Code] = invKeys
|
|
|
|
app.confirmationKeysLock.Unlock()
|
2024-08-20 20:33:43 +00:00
|
|
|
|
|
|
|
// These don't need to complete anytime soon
|
|
|
|
// wg.Wait()
|
2024-08-03 20:23:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) InviteProxy(gc *gin.Context) {
|
2023-06-16 13:43:37 +00:00
|
|
|
app.pushResources(gc, FormPage)
|
|
|
|
lang := app.getLang(gc, FormPage, app.storage.lang.chosenUserLang)
|
2024-08-03 20:23:59 +00:00
|
|
|
|
2020-07-31 12:03:36 +00:00
|
|
|
/* Don't actually check if the invite is valid, just if it exists, just so the page loads quicker. Invite is actually checked on submit anyway. */
|
2020-08-16 12:36:54 +00:00
|
|
|
// if app.checkInvite(code, false, "") {
|
2024-08-03 20:23:59 +00:00
|
|
|
invite, ok := app.storage.GetInvitesKey(gc.Param("invCode"))
|
2021-01-30 19:19:12 +00:00
|
|
|
if !ok {
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, 404, "invalidCode.html", gin.H{
|
2023-06-21 20:22:05 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
2021-01-05 18:16:23 +00:00
|
|
|
"cssClass": app.cssClass,
|
2022-01-08 16:42:36 +00:00
|
|
|
"cssVersion": cssVersion,
|
2020-09-23 19:14:16 +00:00
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
2020-07-31 12:03:36 +00:00
|
|
|
})
|
2021-01-30 19:19:12 +00:00
|
|
|
return
|
2020-07-31 11:48:37 +00:00
|
|
|
}
|
2023-06-21 20:14:41 +00:00
|
|
|
|
2024-08-03 20:23:59 +00:00
|
|
|
if key := gc.Query("key"); key != "" && app.config.Section("email_confirmation").Key("enabled").MustBool(false) {
|
|
|
|
app.NewUserFromConfirmationKey(invite, key, lang, gc)
|
2021-01-30 19:19:12 +00:00
|
|
|
return
|
|
|
|
}
|
2024-08-03 20:23:59 +00:00
|
|
|
|
|
|
|
email := invite.SendTo
|
2021-05-23 15:16:31 +00:00
|
|
|
if strings.Contains(email, "Failed") || !strings.Contains(email, "@") {
|
2021-01-30 19:19:12 +00:00
|
|
|
email = ""
|
|
|
|
}
|
2021-11-17 16:49:26 +00:00
|
|
|
telegram := telegramEnabled && app.config.Section("telegram").Key("show_on_reg").MustBool(true)
|
|
|
|
discord := discordEnabled && app.config.Section("discord").Key("show_on_reg").MustBool(true)
|
|
|
|
matrix := matrixEnabled && app.config.Section("matrix").Key("show_on_reg").MustBool(true)
|
|
|
|
|
2024-08-13 19:39:06 +00:00
|
|
|
userPageAddress := fmt.Sprintf("%s/my/account", app.ExternalURI)
|
2023-06-22 20:57:19 +00:00
|
|
|
|
2023-09-07 19:19:25 +00:00
|
|
|
fromUser := ""
|
2024-08-03 20:23:59 +00:00
|
|
|
if invite.ReferrerJellyfinID != "" {
|
2024-08-06 13:48:31 +00:00
|
|
|
sender, err := app.jf.UserByID(invite.ReferrerJellyfinID, false)
|
|
|
|
if err == nil {
|
2023-09-07 19:19:25 +00:00
|
|
|
fromUser = sender.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 00:08:12 +00:00
|
|
|
data := gin.H{
|
2023-02-02 10:34:22 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"cssVersion": cssVersion,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
"helpMessage": app.config.Section("ui").Key("help_message").String(),
|
|
|
|
"successMessage": app.config.Section("ui").Key("success_message").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),
|
|
|
|
"requirements": app.validator.getCriteria(),
|
|
|
|
"email": email,
|
|
|
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
2023-06-16 13:43:37 +00:00
|
|
|
"strings": app.storage.lang.User[lang].Strings,
|
|
|
|
"validationStrings": app.storage.lang.User[lang].validationStringsJSON,
|
|
|
|
"notifications": app.storage.lang.User[lang].notificationsJSON,
|
2024-08-03 20:23:59 +00:00
|
|
|
"code": invite.Code,
|
2023-02-02 10:34:22 +00:00
|
|
|
"confirmation": app.config.Section("email_confirmation").Key("enabled").MustBool(false),
|
2024-08-03 20:23:59 +00:00
|
|
|
"userExpiry": invite.UserExpiry,
|
|
|
|
"userExpiryMonths": invite.UserMonths,
|
|
|
|
"userExpiryDays": invite.UserDays,
|
|
|
|
"userExpiryHours": invite.UserHours,
|
|
|
|
"userExpiryMinutes": invite.UserMinutes,
|
2023-06-16 13:43:37 +00:00
|
|
|
"userExpiryMessage": app.storage.lang.User[lang].Strings.get("yourAccountIsValidUntil"),
|
2023-02-02 10:34:22 +00:00
|
|
|
"langName": lang,
|
|
|
|
"passwordReset": false,
|
2024-07-28 18:32:48 +00:00
|
|
|
"customSuccessCard": false,
|
2023-02-02 10:34:22 +00:00
|
|
|
"telegramEnabled": telegram,
|
|
|
|
"discordEnabled": discord,
|
|
|
|
"matrixEnabled": matrix,
|
|
|
|
"emailRequired": app.config.Section("email").Key("required").MustBool(false),
|
|
|
|
"captcha": app.config.Section("captcha").Key("enabled").MustBool(false),
|
2023-06-15 16:11:27 +00:00
|
|
|
"reCAPTCHA": app.config.Section("captcha").Key("recaptcha").MustBool(false),
|
|
|
|
"reCAPTCHASiteKey": app.config.Section("captcha").Key("recaptcha_site_key").MustString(""),
|
2023-06-22 09:11:56 +00:00
|
|
|
"userPageEnabled": app.config.Section("user_page").Key("enabled").MustBool(false),
|
2023-06-22 20:57:19 +00:00
|
|
|
"userPageAddress": userPageAddress,
|
2023-09-07 19:19:25 +00:00
|
|
|
"fromUser": fromUser,
|
2021-05-07 00:08:12 +00:00
|
|
|
}
|
2021-11-17 16:49:26 +00:00
|
|
|
if telegram {
|
2021-05-07 00:08:12 +00:00
|
|
|
data["telegramPIN"] = app.telegram.NewAuthToken()
|
|
|
|
data["telegramUsername"] = app.telegram.username
|
|
|
|
data["telegramURL"] = app.telegram.link
|
|
|
|
data["telegramRequired"] = app.config.Section("telegram").Key("required").MustBool(false)
|
|
|
|
}
|
2021-11-17 16:49:26 +00:00
|
|
|
if matrix {
|
2021-05-29 16:43:11 +00:00
|
|
|
data["matrixRequired"] = app.config.Section("matrix").Key("required").MustBool(false)
|
|
|
|
data["matrixUser"] = app.matrix.userID
|
|
|
|
}
|
2021-11-17 16:49:26 +00:00
|
|
|
if discord {
|
2021-05-21 20:35:25 +00:00
|
|
|
data["discordPIN"] = app.discord.NewAuthToken()
|
|
|
|
data["discordUsername"] = app.discord.username
|
|
|
|
data["discordRequired"] = app.config.Section("discord").Key("required").MustBool(false)
|
2023-06-16 13:43:37 +00:00
|
|
|
data["discordSendPINMessage"] = template.HTML(app.storage.lang.User[lang].Strings.template("sendPINDiscord", tmpl{
|
2022-01-30 16:47:29 +00:00
|
|
|
"command": `<span class="text-black dark:text-white font-mono">/` + app.config.Section("discord").Key("start_command").MustString("start") + `</span>`,
|
2021-05-21 20:35:25 +00:00
|
|
|
"server_channel": app.discord.serverChannelName,
|
|
|
|
}))
|
2021-05-23 18:50:03 +00:00
|
|
|
data["discordServerName"] = app.discord.serverName
|
2024-08-03 20:23:59 +00:00
|
|
|
data["discordInviteLink"] = app.discord.InviteChannel.Name != ""
|
2021-05-21 20:35:25 +00:00
|
|
|
}
|
2024-07-28 18:32:48 +00:00
|
|
|
if msg, ok := app.storage.GetCustomContentKey("PostSignupCard"); ok && msg.Enabled {
|
|
|
|
data["customSuccessCard"] = true
|
|
|
|
// We don't template here, since the username is only known after login.
|
|
|
|
data["customSuccessCardContent"] = template.HTML(markdown.ToHTML(
|
|
|
|
[]byte(templateEmail(
|
|
|
|
msg.Content,
|
|
|
|
msg.Variables,
|
|
|
|
msg.Conditionals,
|
|
|
|
map[string]interface{}{
|
|
|
|
"username": "{username}",
|
|
|
|
"myAccountURL": userPageAddress,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
), nil, markdownRenderer,
|
|
|
|
))
|
|
|
|
}
|
2021-05-21 20:35:25 +00:00
|
|
|
|
|
|
|
// if discordEnabled {
|
|
|
|
// pin := ""
|
|
|
|
// for _, token := range app.discord.tokens {
|
|
|
|
// if
|
2021-05-07 00:08:12 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "form-loader.html", data)
|
2020-07-31 11:48:37 +00:00
|
|
|
}
|
2020-07-31 12:03:36 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) NoRouteHandler(gc *gin.Context) {
|
2023-06-16 13:43:37 +00:00
|
|
|
app.pushResources(gc, OtherPage)
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, 404, "404.html", gin.H{
|
2023-06-21 20:22:05 +00:00
|
|
|
"urlBase": app.getURLBase(gc),
|
2021-01-05 18:16:23 +00:00
|
|
|
"cssClass": app.cssClass,
|
2022-01-08 16:42:36 +00:00
|
|
|
"cssVersion": cssVersion,
|
2020-08-16 12:36:54 +00:00
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
2020-07-31 12:03:36 +00:00
|
|
|
})
|
|
|
|
}
|