mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-11-10 04:10:10 +00:00
Compare commits
No commits in common. "f07c60afb0799bf8550c9d268b08ba34bcd89de9" and "3b3f37365a51b18fcf43fbfe638ba964824c954b" have entirely different histories.
f07c60afb0
...
3b3f37365a
@ -275,7 +275,6 @@ func (app *appContext) ModifyMyEmail(gc *gin.Context) {
|
|||||||
// @Failure 500 {object} boolResponse
|
// @Failure 500 {object} boolResponse
|
||||||
// @Param invCode path string true "invite Code"
|
// @Param invCode path string true "invite Code"
|
||||||
// @Router /my/discord/invite [get]
|
// @Router /my/discord/invite [get]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) MyDiscordServerInvite(gc *gin.Context) {
|
func (app *appContext) MyDiscordServerInvite(gc *gin.Context) {
|
||||||
if app.discord.inviteChannelName == "" {
|
if app.discord.inviteChannelName == "" {
|
||||||
@ -296,7 +295,6 @@ func (app *appContext) MyDiscordServerInvite(gc *gin.Context) {
|
|||||||
// @Failure 400 {object} stringResponse
|
// @Failure 400 {object} stringResponse
|
||||||
// Param service path string true "discord/telegram"
|
// Param service path string true "discord/telegram"
|
||||||
// @Router /my/pin/{service} [get]
|
// @Router /my/pin/{service} [get]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) GetMyPIN(gc *gin.Context) {
|
func (app *appContext) GetMyPIN(gc *gin.Context) {
|
||||||
service := gc.Param("service")
|
service := gc.Param("service")
|
||||||
@ -321,7 +319,6 @@ func (app *appContext) GetMyPIN(gc *gin.Context) {
|
|||||||
// @Failure 401 {object} boolResponse
|
// @Failure 401 {object} boolResponse
|
||||||
// @Param pin path string true "PIN code to check"
|
// @Param pin path string true "PIN code to check"
|
||||||
// @Router /my/discord/verified/{pin} [get]
|
// @Router /my/discord/verified/{pin} [get]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) MyDiscordVerifiedInvite(gc *gin.Context) {
|
func (app *appContext) MyDiscordVerifiedInvite(gc *gin.Context) {
|
||||||
pin := gc.Param("pin")
|
pin := gc.Param("pin")
|
||||||
@ -350,7 +347,6 @@ func (app *appContext) MyDiscordVerifiedInvite(gc *gin.Context) {
|
|||||||
// @Failure 401 {object} boolResponse
|
// @Failure 401 {object} boolResponse
|
||||||
// @Param pin path string true "PIN code to check"
|
// @Param pin path string true "PIN code to check"
|
||||||
// @Router /my/telegram/verified/{pin} [get]
|
// @Router /my/telegram/verified/{pin} [get]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) MyTelegramVerifiedInvite(gc *gin.Context) {
|
func (app *appContext) MyTelegramVerifiedInvite(gc *gin.Context) {
|
||||||
pin := gc.Param("pin")
|
pin := gc.Param("pin")
|
||||||
@ -390,7 +386,6 @@ func (app *appContext) MyTelegramVerifiedInvite(gc *gin.Context) {
|
|||||||
// @Failure 500 {object} boolResponse
|
// @Failure 500 {object} boolResponse
|
||||||
// @Param MatrixSendPINDTO body MatrixSendPINDTO true "User's Matrix ID."
|
// @Param MatrixSendPINDTO body MatrixSendPINDTO true "User's Matrix ID."
|
||||||
// @Router /my/matrix/user [post]
|
// @Router /my/matrix/user [post]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) MatrixSendMyPIN(gc *gin.Context) {
|
func (app *appContext) MatrixSendMyPIN(gc *gin.Context) {
|
||||||
var req MatrixSendPINDTO
|
var req MatrixSendPINDTO
|
||||||
@ -424,7 +419,6 @@ func (app *appContext) MatrixSendMyPIN(gc *gin.Context) {
|
|||||||
// @Param invCode path string true "invite Code"
|
// @Param invCode path string true "invite Code"
|
||||||
// @Param userID path string true "Matrix User ID"
|
// @Param userID path string true "Matrix User ID"
|
||||||
// @Router /my/matrix/verified/{userID}/{pin} [get]
|
// @Router /my/matrix/verified/{userID}/{pin} [get]
|
||||||
// @Security Bearer
|
|
||||||
// @tags User Page
|
// @tags User Page
|
||||||
func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) {
|
func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) {
|
||||||
userID := gc.Param("userID")
|
userID := gc.Param("userID")
|
||||||
@ -458,8 +452,7 @@ func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} boolResponse
|
// @Success 200 {object} boolResponse
|
||||||
// @Router /my/discord [delete]
|
// @Router /my/discord [delete]
|
||||||
// @Security Bearer
|
// @Tags Users
|
||||||
// @Tags User Page
|
|
||||||
func (app *appContext) UnlinkMyDiscord(gc *gin.Context) {
|
func (app *appContext) UnlinkMyDiscord(gc *gin.Context) {
|
||||||
app.storage.DeleteDiscordKey(gc.GetString("jfId"))
|
app.storage.DeleteDiscordKey(gc.GetString("jfId"))
|
||||||
respondBool(200, true, gc)
|
respondBool(200, true, gc)
|
||||||
@ -469,8 +462,7 @@ func (app *appContext) UnlinkMyDiscord(gc *gin.Context) {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} boolResponse
|
// @Success 200 {object} boolResponse
|
||||||
// @Router /my/telegram [delete]
|
// @Router /my/telegram [delete]
|
||||||
// @Security Bearer
|
// @Tags Users
|
||||||
// @Tags User Page
|
|
||||||
func (app *appContext) UnlinkMyTelegram(gc *gin.Context) {
|
func (app *appContext) UnlinkMyTelegram(gc *gin.Context) {
|
||||||
app.storage.DeleteTelegramKey(gc.GetString("jfId"))
|
app.storage.DeleteTelegramKey(gc.GetString("jfId"))
|
||||||
respondBool(200, true, gc)
|
respondBool(200, true, gc)
|
||||||
@ -480,8 +472,7 @@ func (app *appContext) UnlinkMyTelegram(gc *gin.Context) {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} boolResponse
|
// @Success 200 {object} boolResponse
|
||||||
// @Router /my/matrix [delete]
|
// @Router /my/matrix [delete]
|
||||||
// @Security Bearer
|
// @Tags Users
|
||||||
// @Tags User Page
|
|
||||||
func (app *appContext) UnlinkMyMatrix(gc *gin.Context) {
|
func (app *appContext) UnlinkMyMatrix(gc *gin.Context) {
|
||||||
app.storage.DeleteMatrixKey(gc.GetString("jfId"))
|
app.storage.DeleteMatrixKey(gc.GetString("jfId"))
|
||||||
respondBool(200, true, gc)
|
respondBool(200, true, gc)
|
||||||
@ -494,7 +485,7 @@ func (app *appContext) UnlinkMyMatrix(gc *gin.Context) {
|
|||||||
// @Failure 400 {object} boolResponse
|
// @Failure 400 {object} boolResponse
|
||||||
// @Failure 500 {object} boolResponse
|
// @Failure 500 {object} boolResponse
|
||||||
// @Router /my/password/reset/{address} [post]
|
// @Router /my/password/reset/{address} [post]
|
||||||
// @Tags User Page
|
// @tags Users
|
||||||
func (app *appContext) ResetMyPassword(gc *gin.Context) {
|
func (app *appContext) ResetMyPassword(gc *gin.Context) {
|
||||||
// All requests should take 1 second, to make it harder to tell if a success occured or not.
|
// All requests should take 1 second, to make it harder to tell if a success occured or not.
|
||||||
timerWait := make(chan bool)
|
timerWait := make(chan bool)
|
||||||
@ -560,70 +551,3 @@ func (app *appContext) ResetMyPassword(gc *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Change your password, given the old one and the new one.
|
|
||||||
// @Produce json
|
|
||||||
// @Param ChangeMyPasswordDTO body ChangeMyPasswordDTO true "User's old & new passwords."
|
|
||||||
// @Success 204 {object} boolResponse
|
|
||||||
// @Failure 400 {object} PasswordValidation
|
|
||||||
// @Failure 401 {object} boolResponse
|
|
||||||
// @Failure 500 {object} boolResponse
|
|
||||||
// @Router /my/password [post]
|
|
||||||
// @Security Bearer
|
|
||||||
// @Tags User Page
|
|
||||||
func (app *appContext) ChangeMyPassword(gc *gin.Context) {
|
|
||||||
var req ChangeMyPasswordDTO
|
|
||||||
gc.BindJSON(&req)
|
|
||||||
if req.Old == "" || req.New == "" {
|
|
||||||
respondBool(400, false, gc)
|
|
||||||
}
|
|
||||||
validation := app.validator.validate(req.New)
|
|
||||||
for _, val := range validation {
|
|
||||||
if !val {
|
|
||||||
app.debug.Printf("%s: Change password failed: Invalid password", gc.GetString("jfId"))
|
|
||||||
gc.JSON(400, validation)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
user, status, err := app.jf.UserByID(gc.GetString("jfId"), false)
|
|
||||||
if status != 200 || err != nil {
|
|
||||||
app.err.Printf("Failed to change password: couldn't find user (%d): %+v", status, err)
|
|
||||||
respondBool(500, false, gc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Authenticate as user to confirm old password.
|
|
||||||
user, status, err = app.authJf.Authenticate(user.Name, req.Old)
|
|
||||||
if status != 200 || err != nil {
|
|
||||||
respondBool(401, false, gc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
status, err = app.jf.SetPassword(gc.GetString("jfId"), req.Old, req.New)
|
|
||||||
if (status != 200 && status != 204) || err != nil {
|
|
||||||
respondBool(500, false, gc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
|
||||||
func() {
|
|
||||||
ombiUser, status, err := app.getOmbiUser(gc.GetString("jfId"))
|
|
||||||
if status != 200 || err != nil {
|
|
||||||
app.err.Printf("Failed to get user \"%s\" from ombi (%d): %v", user.Name, status, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ombiUser["password"] = req.New
|
|
||||||
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"])
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
cookie, err := gc.Cookie("user-refresh")
|
|
||||||
if err == nil {
|
|
||||||
app.invalidTokens = append(app.invalidTokens, cookie)
|
|
||||||
gc.SetCookie("refresh", "invalid", -1, "/my", gc.Request.URL.Hostname(), true, true)
|
|
||||||
} else {
|
|
||||||
app.debug.Printf("Couldn't get cookies: %s", err)
|
|
||||||
}
|
|
||||||
respondBool(204, true, gc)
|
|
||||||
}
|
|
||||||
|
@ -463,7 +463,6 @@ func (app *appContext) NewUser(gc *gin.Context) {
|
|||||||
for _, val := range validation {
|
for _, val := range validation {
|
||||||
if !val {
|
if !val {
|
||||||
valid = false
|
valid = false
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
|
1
api.go
1
api.go
@ -143,7 +143,6 @@ func (app *appContext) ResetSetPassword(gc *gin.Context) {
|
|||||||
respondBool(status, false, gc)
|
respondBool(status, false, gc)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete(app.internalPWRs, req.PIN)
|
|
||||||
} else {
|
} else {
|
||||||
resp, status, err := app.jf.ResetPassword(req.PIN)
|
resp, status, err := app.jf.ResetPassword(req.PIN)
|
||||||
if status != 200 || err != nil || !resp.Success {
|
if status != 200 || err != nil || !resp.Success {
|
||||||
|
@ -394,7 +394,7 @@
|
|||||||
"value": "",
|
"value": "",
|
||||||
"depends_true": "enabled",
|
"depends_true": "enabled",
|
||||||
"required": "false",
|
"required": "false",
|
||||||
"description": "Jellyfin Login must be enabled to use this feature, and password resets with a link must be enabled for self-service.",
|
"description": "Jellyfin Login must be enabled to use this feature.",
|
||||||
"style": "critical"
|
"style": "critical"
|
||||||
},
|
},
|
||||||
"edit_note": {
|
"edit_note": {
|
||||||
|
@ -124,7 +124,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex-initial">
|
<div class="flex-initial">
|
||||||
<div class="card ~neutral @low mb-4">
|
<div class="card ~neutral @low mb-4">
|
||||||
<span class="label supra">{{ .strings.passwordRequirementsHeader }}</span>
|
<span class="label supra" for="inv-uses">{{ .strings.passwordRequirementsHeader }}</span>
|
||||||
<ul>
|
<ul>
|
||||||
{{ range $key, $value := .requirements }}
|
{{ range $key, $value := .requirements }}
|
||||||
<li class="" id="requirement-{{ $key }}" min="{{ $value }}">
|
<li class="" id="requirement-{{ $key }}" min="{{ $value }}">
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
window.matrixEnabled = {{ .matrixEnabled }};
|
window.matrixEnabled = {{ .matrixEnabled }};
|
||||||
window.matrixRequired = {{ .matrixRequired }};
|
window.matrixRequired = {{ .matrixRequired }};
|
||||||
window.matrixUserID = "{{ .matrixUser }}";
|
window.matrixUserID = "{{ .matrixUser }}";
|
||||||
window.validationStrings = JSON.parse({{ .validationStrings }});
|
|
||||||
</script>
|
</script>
|
||||||
{{ template "header.html" . }}
|
{{ template "header.html" . }}
|
||||||
<title>{{ .lang.Strings.myAccount }}</title>
|
<title>{{ .lang.Strings.myAccount }}</title>
|
||||||
@ -114,36 +113,6 @@
|
|||||||
<span class="heading mb-2">{{ .strings.contactMethods }}</span>
|
<span class="heading mb-2">{{ .strings.contactMethods }}</span>
|
||||||
<div class="content flex justify-between flex-col h-100"></div>
|
<div class="content flex justify-between flex-col h-100"></div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<div class="card @low dark:~d_neutral content" id="card-password">
|
|
||||||
<span class="heading row mb-2">{{ .strings.changePassword }}</span>
|
|
||||||
<div class="">
|
|
||||||
<div class="my-2">
|
|
||||||
<span class="label supra row">{{ .strings.passwordRequirementsHeader }}</span>
|
|
||||||
<ul>
|
|
||||||
{{ range $key, $value := .requirements }}
|
|
||||||
<li class="" id="requirement-{{ $key }}" min="{{ $value }}">
|
|
||||||
<span class="badge lg ~positive requirement-valid"></span> <span class="content requirement-content"></span>
|
|
||||||
</li>
|
|
||||||
{{ end }}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="my-2">
|
|
||||||
<label class="label supra" for="user-old-password">{{ .strings.oldPassword }}</label>
|
|
||||||
<input type="password" class="input ~neutral @low mt-2 mb-4" placeholder="{{ .strings.password }}" id="user-old-password" aria-label="{{ .strings.oldPassword }}">
|
|
||||||
<label class="label supra" for="user-new-password">{{ .strings.newPassword }}</label>
|
|
||||||
<input type="password" class="input ~neutral @low mt-2 mb-4" placeholder="{{ .strings.password }}" id="user-new-password" aria-label="{{ .strings.newPassword }}">
|
|
||||||
|
|
||||||
<label class="label supra" for="user-reenter-password">{{ .strings.reEnterPassword }}</label>
|
|
||||||
<input type="password" class="input ~neutral @low mt-2 mb-4" placeholder="{{ .strings.password }}" id="user-reenter-new-password" aria-label="{{ .strings.reEnterPassword }}">
|
|
||||||
<span class="button ~info @low full-width center mt-4" id="user-password-submit">
|
|
||||||
{{ .strings.changePassword }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="card @low dark:~d_neutral unfocused" id="card-status">
|
<div class="card @low dark:~d_neutral unfocused" id="card-status">
|
||||||
<span class="heading mb-2">{{ .strings.expiry }}</span>
|
<span class="heading mb-2">{{ .strings.expiry }}</span>
|
||||||
<aside class="aside ~warning user-expiry my-4"></aside>
|
<aside class="aside ~warning user-expiry my-4"></aside>
|
||||||
@ -151,7 +120,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<script src="{{ .urlBase }}/js/user.js" type="module"></script>
|
<script src="{{ .urlBase }}/js/user.js" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
"accountDetails": "Details",
|
"accountDetails": "Details",
|
||||||
"emailAddress": "Email",
|
"emailAddress": "Email",
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"oldPassword": "Old Password",
|
|
||||||
"newPassword": "New Password",
|
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"reEnterPassword": "Re-enter Password",
|
"reEnterPassword": "Re-enter Password",
|
||||||
"reEnterPasswordInvalid": "Passwords are not the same.",
|
"reEnterPasswordInvalid": "Passwords are not the same.",
|
||||||
@ -33,8 +31,7 @@
|
|||||||
"resetPasswordThroughJellyfin": "To reset your password, visit {jfLink} and press the \"Forgot Password\" button.",
|
"resetPasswordThroughJellyfin": "To reset your password, visit {jfLink} and press the \"Forgot Password\" button.",
|
||||||
"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.",
|
"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.",
|
"resetSent": "Reset Sent.",
|
||||||
"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.",
|
"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."
|
||||||
"changePassword": "Change Password"
|
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"errorUserExists": "User already exists.",
|
"errorUserExists": "User already exists.",
|
||||||
@ -50,8 +47,6 @@
|
|||||||
"errorCaptcha": "Captcha incorrect.",
|
"errorCaptcha": "Captcha incorrect.",
|
||||||
"errorPassword": "Check password requirements.",
|
"errorPassword": "Check password requirements.",
|
||||||
"errorNoMatch": "Passwords don't match.",
|
"errorNoMatch": "Passwords don't match.",
|
||||||
"errorOldPassword": "Old password incorrect.",
|
|
||||||
"passwordChanged": "Password Changed.",
|
|
||||||
"verified": "Account verified."
|
"verified": "Account verified."
|
||||||
},
|
},
|
||||||
"validationStrings": {
|
"validationStrings": {
|
||||||
|
@ -408,8 +408,3 @@ const (
|
|||||||
type GetMyPINDTO struct {
|
type GetMyPINDTO struct {
|
||||||
PIN string `json:"pin"`
|
PIN string `json:"pin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChangeMyPasswordDTO struct {
|
|
||||||
Old string `json:"old"`
|
|
||||||
New string `json:"new"`
|
|
||||||
}
|
|
||||||
|
@ -241,7 +241,6 @@ func (app *appContext) loadRoutes(router *gin.Engine) {
|
|||||||
user.DELETE(p+"/discord", app.UnlinkMyDiscord)
|
user.DELETE(p+"/discord", app.UnlinkMyDiscord)
|
||||||
user.DELETE(p+"/telegram", app.UnlinkMyTelegram)
|
user.DELETE(p+"/telegram", app.UnlinkMyTelegram)
|
||||||
user.DELETE(p+"/matrix", app.UnlinkMyMatrix)
|
user.DELETE(p+"/matrix", app.UnlinkMyMatrix)
|
||||||
user.POST(p+"/password", app.ChangeMyPassword)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
ts/form.ts
40
ts/form.ts
@ -2,7 +2,7 @@ import { Modal } from "./modules/modal.js";
|
|||||||
import { notificationBox, whichAnimationEvent } from "./modules/common.js";
|
import { notificationBox, whichAnimationEvent } from "./modules/common.js";
|
||||||
import { _get, _post, toggleLoader, addLoader, removeLoader, toDateString } from "./modules/common.js";
|
import { _get, _post, toggleLoader, addLoader, removeLoader, toDateString } from "./modules/common.js";
|
||||||
import { loadLangSelector } from "./modules/lang.js";
|
import { loadLangSelector } from "./modules/lang.js";
|
||||||
import { Validator, ValidatorConf, ValidatorRespDTO } from "./modules/validator.js";
|
import { initValidator } from "./modules/validator.js";
|
||||||
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
|
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
|
||||||
|
|
||||||
interface formWindow extends Window {
|
interface formWindow extends Window {
|
||||||
@ -69,7 +69,7 @@ if (window.telegramEnabled) {
|
|||||||
const radio = document.getElementById("contact-via-telegram") as HTMLInputElement;
|
const radio = document.getElementById("contact-via-telegram") as HTMLInputElement;
|
||||||
radio.parentElement.classList.remove("unfocused");
|
radio.parentElement.classList.remove("unfocused");
|
||||||
radio.checked = true;
|
radio.checked = true;
|
||||||
validator.validate();
|
validatorFunc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ if (window.discordEnabled) {
|
|||||||
const radio = document.getElementById("contact-via-discord") as HTMLInputElement;
|
const radio = document.getElementById("contact-via-discord") as HTMLInputElement;
|
||||||
radio.parentElement.classList.remove("unfocused")
|
radio.parentElement.classList.remove("unfocused")
|
||||||
radio.checked = true;
|
radio.checked = true;
|
||||||
validator.validate();
|
validatorFunc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ if (window.matrixEnabled) {
|
|||||||
const radio = document.getElementById("contact-via-matrix") as HTMLInputElement;
|
const radio = document.getElementById("contact-via-matrix") as HTMLInputElement;
|
||||||
radio.parentElement.classList.remove("unfocused");
|
radio.parentElement.classList.remove("unfocused");
|
||||||
radio.checked = true;
|
radio.checked = true;
|
||||||
validator.validate();
|
validatorFunc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ if (window.userExpiryEnabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const form = document.getElementById("form-create") as HTMLFormElement;
|
const form = document.getElementById("form-create") as HTMLFormElement;
|
||||||
const submitInput = form.querySelector("input[type=submit]") as HTMLInputElement;
|
const submitButton = form.querySelector("input[type=submit]") as HTMLInputElement;
|
||||||
const submitSpan = form.querySelector("span.submit") as HTMLSpanElement;
|
const submitSpan = form.querySelector("span.submit") as HTMLSpanElement;
|
||||||
const submitText = submitSpan.textContent;
|
const submitText = submitSpan.textContent;
|
||||||
let usernameField = document.getElementById("create-username") as HTMLInputElement;
|
let usernameField = document.getElementById("create-username") as HTMLInputElement;
|
||||||
@ -242,19 +242,17 @@ interface GreCAPTCHA {
|
|||||||
|
|
||||||
declare var grecaptcha: GreCAPTCHA
|
declare var grecaptcha: GreCAPTCHA
|
||||||
|
|
||||||
let validatorConf: ValidatorConf = {
|
let r = initValidator(passwordField, rePasswordField, submitButton, submitSpan, baseValidator);
|
||||||
passwordField: passwordField,
|
var requirements = r[0];
|
||||||
rePasswordField: rePasswordField,
|
var validatorFunc = r[1] as () => void;
|
||||||
submitInput: submitInput,
|
|
||||||
submitButton: submitSpan,
|
|
||||||
validatorFunc: baseValidator
|
|
||||||
};
|
|
||||||
|
|
||||||
let validator = new Validator(validatorConf);
|
|
||||||
var requirements = validator.requirements;
|
|
||||||
|
|
||||||
if (window.emailRequired) {
|
if (window.emailRequired) {
|
||||||
emailField.addEventListener("keyup", validator.validate)
|
emailField.addEventListener("keyup", validatorFunc)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface respDTO {
|
||||||
|
response: boolean;
|
||||||
|
error: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface sendDTO {
|
interface sendDTO {
|
||||||
@ -289,7 +287,7 @@ const genCaptcha = () => {
|
|||||||
if (window.captcha && !window.reCAPTCHA) {
|
if (window.captcha && !window.reCAPTCHA) {
|
||||||
genCaptcha();
|
genCaptcha();
|
||||||
(document.getElementById("captcha-regen") as HTMLSpanElement).onclick = genCaptcha;
|
(document.getElementById("captcha-regen") as HTMLSpanElement).onclick = genCaptcha;
|
||||||
captchaInput.onkeyup = validator.validate;
|
captchaInput.onkeyup = validatorFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = (event: SubmitEvent) => {
|
const create = (event: SubmitEvent) => {
|
||||||
@ -335,11 +333,11 @@ const create = (event: SubmitEvent) => {
|
|||||||
}
|
}
|
||||||
_post("/newUser", send, (req: XMLHttpRequest) => {
|
_post("/newUser", send, (req: XMLHttpRequest) => {
|
||||||
if (req.readyState == 4) {
|
if (req.readyState == 4) {
|
||||||
let vals = req.response as ValidatorRespDTO;
|
let vals = req.response as respDTO;
|
||||||
let valid = true;
|
let valid = true;
|
||||||
for (let type in vals) {
|
for (let type in vals) {
|
||||||
if (requirements[type]) requirements[type].valid = vals[type];
|
if (requirements[type]) { requirements[type].valid = vals[type]; }
|
||||||
if (!vals[type]) valid = false;
|
if (!vals[type]) { valid = false; }
|
||||||
}
|
}
|
||||||
if (req.status == 200 && valid) {
|
if (req.status == 200 && valid) {
|
||||||
if (window.redirectToJellyfin == true) {
|
if (window.redirectToJellyfin == true) {
|
||||||
@ -388,6 +386,6 @@ const create = (event: SubmitEvent) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
validator.validate();
|
validatorFunc();
|
||||||
|
|
||||||
form.onsubmit = create;
|
form.onsubmit = create;
|
||||||
|
@ -9,11 +9,6 @@ interface pwValString {
|
|||||||
plural: string;
|
plural: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ValidatorRespDTO {
|
|
||||||
response: boolean;
|
|
||||||
error: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface pwValStrings {
|
interface pwValStrings {
|
||||||
length: pwValString;
|
length: pwValString;
|
||||||
uppercase: pwValString;
|
uppercase: pwValString;
|
||||||
@ -65,21 +60,8 @@ class Requirement {
|
|||||||
validate = (count: number) => { this.valid = (count >= this._minCount); }
|
validate = (count: number) => { this.valid = (count >= this._minCount); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ValidatorConf {
|
export function initValidator(passwordField: HTMLInputElement, rePasswordField: HTMLInputElement, submitButton: HTMLInputElement, submitSpan: HTMLSpanElement, validatorFunc?: (oncomplete: (valid: boolean) => void) => void): ({ [category: string]: Requirement }|(() => void))[] {
|
||||||
passwordField: HTMLInputElement;
|
var defaultPwValStrings: pwValStrings = {
|
||||||
rePasswordField: HTMLInputElement;
|
|
||||||
submitInput?: HTMLInputElement;
|
|
||||||
submitButton: HTMLSpanElement;
|
|
||||||
validatorFunc?: (oncomplete: (valid: boolean) => void) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Validation { [name: string]: number }
|
|
||||||
export interface Requirements { [category: string]: Requirement };
|
|
||||||
|
|
||||||
export class Validator {
|
|
||||||
private _conf: ValidatorConf;
|
|
||||||
private _requirements: Requirements = {};
|
|
||||||
private _defaultPwValStrings: pwValStrings = {
|
|
||||||
length: {
|
length: {
|
||||||
singular: "Must have at least {n} character",
|
singular: "Must have at least {n} character",
|
||||||
plural: "Must have at least {n} characters"
|
plural: "Must have at least {n} characters"
|
||||||
@ -100,34 +82,39 @@ export class Validator {
|
|||||||
singular: "Must have at least {n} special character",
|
singular: "Must have at least {n} special character",
|
||||||
plural: "Must have at least {n} special characters"
|
plural: "Must have at least {n} special characters"
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private _checkPasswords = () => {
|
|
||||||
return this._conf.passwordField.value == this._conf.rePasswordField.value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate = () => {
|
const checkPasswords = () => {
|
||||||
const pw = this._checkPasswords();
|
return passwordField.value == rePasswordField.value;
|
||||||
this._conf.validatorFunc((valid: boolean) => {
|
}
|
||||||
|
|
||||||
|
const checkValidity = () => {
|
||||||
|
const pw = checkPasswords();
|
||||||
|
validatorFunc((valid: boolean) => {
|
||||||
if (pw && valid) {
|
if (pw && valid) {
|
||||||
this._conf.rePasswordField.setCustomValidity("");
|
rePasswordField.setCustomValidity("");
|
||||||
if (this._conf.submitInput) this._conf.submitInput.disabled = false;
|
submitButton.disabled = false;
|
||||||
this._conf.submitButton.removeAttribute("disabled");
|
submitSpan.removeAttribute("disabled");
|
||||||
} else if (!pw) {
|
} else if (!pw) {
|
||||||
this._conf.rePasswordField.setCustomValidity(window.invalidPassword);
|
rePasswordField.setCustomValidity(window.invalidPassword);
|
||||||
if (this._conf.submitInput) this._conf.submitInput.disabled = true;
|
submitButton.disabled = true;
|
||||||
this._conf.submitButton.setAttribute("disabled", "");
|
submitSpan.setAttribute("disabled", "");
|
||||||
} else {
|
} else {
|
||||||
this._conf.rePasswordField.setCustomValidity("");
|
rePasswordField.setCustomValidity("");
|
||||||
if (this._conf.submitInput) this._conf.submitInput.disabled = true;
|
submitButton.disabled = true;
|
||||||
this._conf.submitButton.setAttribute("disabled", "");
|
submitSpan.setAttribute("disabled", "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private _isInt = (s: string): boolean => { return (s >= '0' && s <= '9'); }
|
rePasswordField.addEventListener("keyup", checkValidity);
|
||||||
|
passwordField.addEventListener("keyup", checkValidity);
|
||||||
|
|
||||||
private _testStrings = (f: pwValString): boolean => {
|
|
||||||
|
// Incredible code right here
|
||||||
|
const isInt = (s: string): boolean => { return (s in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]); }
|
||||||
|
|
||||||
|
const testStrings = (f: pwValString): boolean => {
|
||||||
const testString = (s: string): boolean => {
|
const testString = (s: string): boolean => {
|
||||||
if (s == "" || !s.includes("{n}")) { return false; }
|
if (s == "" || !s.includes("{n}")) { return false; }
|
||||||
return true;
|
return true;
|
||||||
@ -135,12 +122,14 @@ export class Validator {
|
|||||||
return testString(f.singular) && testString(f.plural);
|
return testString(f.singular) && testString(f.plural);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _validate = (s: string): Validation => {
|
interface Validation { [name: string]: number }
|
||||||
|
|
||||||
|
const validate = (s: string): Validation => {
|
||||||
let v: Validation = {};
|
let v: Validation = {};
|
||||||
for (let criteria of ["length", "lowercase", "uppercase", "number", "special"]) { v[criteria] = 0; }
|
for (let criteria of ["length", "lowercase", "uppercase", "number", "special"]) { v[criteria] = 0; }
|
||||||
v["length"] = s.length;
|
v["length"] = s.length;
|
||||||
for (let c of s) {
|
for (let c of s) {
|
||||||
if (this._isInt(c)) { v["number"]++; }
|
if (isInt(c)) { v["number"]++; }
|
||||||
else {
|
else {
|
||||||
const upper = c.toUpperCase();
|
const upper = c.toUpperCase();
|
||||||
if (upper == c.toLowerCase()) { v["special"]++; }
|
if (upper == c.toLowerCase()) { v["special"]++; }
|
||||||
@ -152,37 +141,27 @@ export class Validator {
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
passwordField.addEventListener("keyup", () => {
|
||||||
private _bindRequirements = () => {
|
const v = validate(passwordField.value);
|
||||||
for (let category in window.validationStrings) {
|
for (let criteria in requirements) {
|
||||||
if (!this._testStrings(window.validationStrings[category])) {
|
requirements[criteria].validate(v[criteria]);
|
||||||
window.validationStrings[category] = this._defaultPwValStrings[category];
|
|
||||||
}
|
|
||||||
const el = document.getElementById("requirement-" + category);
|
|
||||||
if (typeof(el) === 'undefined' || el == null) continue;
|
|
||||||
this._requirements[category] = new Requirement(category, el as HTMLLIElement);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
get requirements(): Requirements { return this._requirements };
|
|
||||||
|
|
||||||
constructor(conf: ValidatorConf) {
|
|
||||||
this._conf = conf;
|
|
||||||
if (!(this._conf.validatorFunc)) {
|
|
||||||
this._conf.validatorFunc = (oncomplete: (valid: boolean) => void) => { oncomplete(true); };
|
|
||||||
}
|
|
||||||
this._conf.rePasswordField.addEventListener("keyup", this.validate);
|
|
||||||
this._conf.passwordField.addEventListener("keyup", this.validate);
|
|
||||||
this._conf.passwordField.addEventListener("keyup", () => {
|
|
||||||
const v = this._validate(this._conf.passwordField.value);
|
|
||||||
for (let criteria in this._requirements) {
|
|
||||||
this._requirements[criteria].validate(v[criteria]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var requirements: { [category: string]: Requirement } = {};
|
||||||
|
|
||||||
if (!window.validationStrings) {
|
if (!window.validationStrings) {
|
||||||
window.validationStrings = this._defaultPwValStrings;
|
window.validationStrings = defaultPwValStrings;
|
||||||
} else {
|
} else {
|
||||||
this._bindRequirements();
|
for (let category in window.validationStrings) {
|
||||||
|
if (!testStrings(window.validationStrings[category])) {
|
||||||
|
window.validationStrings[category] = defaultPwValStrings[category];
|
||||||
|
}
|
||||||
|
const el = document.getElementById("requirement-" + category);
|
||||||
|
if (el) {
|
||||||
|
requirements[category] = new Requirement(category, el as HTMLLIElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return [requirements, checkValidity]
|
||||||
|
}
|
||||||
|
16
ts/pwr.ts
16
ts/pwr.ts
@ -1,5 +1,5 @@
|
|||||||
import { Modal } from "./modules/modal.js";
|
import { Modal } from "./modules/modal.js";
|
||||||
import { Validator, ValidatorConf } from "./modules/validator.js";
|
import { initValidator } from "./modules/validator.js";
|
||||||
import { _post, addLoader, removeLoader } from "./modules/common.js";
|
import { _post, addLoader, removeLoader } from "./modules/common.js";
|
||||||
import { loadLangSelector } from "./modules/lang.js";
|
import { loadLangSelector } from "./modules/lang.js";
|
||||||
|
|
||||||
@ -35,22 +35,14 @@ loadLangSelector("pwr");
|
|||||||
declare var window: formWindow;
|
declare var window: formWindow;
|
||||||
|
|
||||||
const form = document.getElementById("form-create") as HTMLFormElement;
|
const form = document.getElementById("form-create") as HTMLFormElement;
|
||||||
const submitInput = form.querySelector("input[type=submit]") as HTMLInputElement;
|
const submitButton = form.querySelector("input[type=submit]") as HTMLInputElement;
|
||||||
const submitSpan = form.querySelector("span.submit") as HTMLSpanElement;
|
const submitSpan = form.querySelector("span.submit") as HTMLSpanElement;
|
||||||
const passwordField = document.getElementById("create-password") as HTMLInputElement;
|
const passwordField = document.getElementById("create-password") as HTMLInputElement;
|
||||||
const rePasswordField = document.getElementById("create-reenter-password") as HTMLInputElement;
|
const rePasswordField = document.getElementById("create-reenter-password") as HTMLInputElement;
|
||||||
|
|
||||||
window.successModal = new Modal(document.getElementById("modal-success"), true);
|
window.successModal = new Modal(document.getElementById("modal-success"), true);
|
||||||
|
|
||||||
let validatorConf: ValidatorConf = {
|
var requirements = initValidator(passwordField, rePasswordField, submitButton, submitSpan)
|
||||||
passwordField: passwordField,
|
|
||||||
rePasswordField: rePasswordField,
|
|
||||||
submitInput: submitInput,
|
|
||||||
submitButton: submitSpan
|
|
||||||
};
|
|
||||||
|
|
||||||
var validator = new Validator(validatorConf);
|
|
||||||
var requirements = validator.requirements;
|
|
||||||
|
|
||||||
interface sendDTO {
|
interface sendDTO {
|
||||||
pin: string;
|
pin: string;
|
||||||
@ -89,5 +81,3 @@ form.onsubmit = (event: Event) => {
|
|||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
validator.validate();
|
|
||||||
|
92
ts/user.ts
92
ts/user.ts
@ -1,10 +1,9 @@
|
|||||||
import { ThemeManager } from "./modules/theme.js";
|
import { ThemeManager } from "./modules/theme.js";
|
||||||
import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
|
import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
|
||||||
import { Modal } from "./modules/modal.js";
|
import { Modal } from "./modules/modal.js";
|
||||||
import { _get, _post, _delete, notificationBox, whichAnimationEvent, toDateString, toggleLoader, addLoader, removeLoader } from "./modules/common.js";
|
import { _get, _post, _delete, notificationBox, whichAnimationEvent, toDateString, toggleLoader } from "./modules/common.js";
|
||||||
import { Login } from "./modules/login.js";
|
import { Login } from "./modules/login.js";
|
||||||
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
|
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
|
||||||
import { Validator, ValidatorConf, ValidatorRespDTO } from "./modules/validator.js";
|
|
||||||
|
|
||||||
interface userWindow extends Window {
|
interface userWindow extends Window {
|
||||||
jellyfinID: string;
|
jellyfinID: string;
|
||||||
@ -89,7 +88,6 @@ const grid = document.querySelector(".grid");
|
|||||||
var rootCard = document.getElementById("card-user");
|
var rootCard = document.getElementById("card-user");
|
||||||
var contactCard = document.getElementById("card-contact");
|
var contactCard = document.getElementById("card-contact");
|
||||||
var statusCard = document.getElementById("card-status");
|
var statusCard = document.getElementById("card-status");
|
||||||
var passwordCard = document.getElementById("card-password");
|
|
||||||
|
|
||||||
interface MyDetailsContactMethod {
|
interface MyDetailsContactMethod {
|
||||||
value: string;
|
value: string;
|
||||||
@ -387,51 +385,6 @@ const matrixConf: MatrixConfiguration = {
|
|||||||
let matrix = new Matrix(matrixConf);
|
let matrix = new Matrix(matrixConf);
|
||||||
|
|
||||||
|
|
||||||
const oldPasswordField = document.getElementById("user-old-password") as HTMLInputElement;
|
|
||||||
const newPasswordField = document.getElementById("user-new-password") as HTMLInputElement;
|
|
||||||
const rePasswordField = document.getElementById("user-reenter-new-password") as HTMLInputElement;
|
|
||||||
const changePasswordButton = document.getElementById("user-password-submit") as HTMLSpanElement;
|
|
||||||
|
|
||||||
let baseValidator = (oncomplete: (valid: boolean) => void): void => {
|
|
||||||
if (oldPasswordField.value.length == 0) return oncomplete(false);
|
|
||||||
oncomplete(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
let validatorConf: ValidatorConf = {
|
|
||||||
passwordField: newPasswordField,
|
|
||||||
rePasswordField: rePasswordField,
|
|
||||||
submitButton: changePasswordButton,
|
|
||||||
validatorFunc: baseValidator
|
|
||||||
};
|
|
||||||
|
|
||||||
let validator = new Validator(validatorConf);
|
|
||||||
// let requirements = validator.requirements;
|
|
||||||
|
|
||||||
oldPasswordField.addEventListener("keyup", validator.validate);
|
|
||||||
changePasswordButton.addEventListener("click", () => {
|
|
||||||
addLoader(changePasswordButton);
|
|
||||||
_post("/my/password", { old: oldPasswordField.value, new: newPasswordField.value }, (req: XMLHttpRequest) => {
|
|
||||||
if (req.readyState != 4) return;
|
|
||||||
removeLoader(changePasswordButton);
|
|
||||||
if (req.status == 400) {
|
|
||||||
window.notifications.customError("errorPassword", window.lang.notif("errorPassword"));
|
|
||||||
} else if (req.status == 500) {
|
|
||||||
window.notifications.customError("errorUnknown", window.lang.notif("errorUnknown"));
|
|
||||||
} else if (req.status == 204) {
|
|
||||||
window.notifications.customSuccess("passwordChanged", window.lang.notif("passwordChanged"));
|
|
||||||
setTimeout(() => { window.location.reload() }, 2000);
|
|
||||||
}
|
|
||||||
}, true, (req: XMLHttpRequest) => {
|
|
||||||
if (req.readyState != 4) return;
|
|
||||||
if (req.status == 401) {
|
|
||||||
removeLoader(changePasswordButton);
|
|
||||||
window.notifications.customError("oldPasswordError", window.lang.notif("errorOldPassword"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// FIXME: Submit & Validate
|
|
||||||
|
|
||||||
document.addEventListener("details-reload", () => {
|
document.addEventListener("details-reload", () => {
|
||||||
_get("/my/details", null, (req: XMLHttpRequest) => {
|
_get("/my/details", null, (req: XMLHttpRequest) => {
|
||||||
if (req.readyState == 4) {
|
if (req.readyState == 4) {
|
||||||
@ -495,10 +448,20 @@ document.addEventListener("details-reload", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof(messageCard) != "undefined" && messageCard != null) {
|
if (typeof(messageCard) != "undefined" && messageCard != null) {
|
||||||
setBestRowSpan(messageCard, false);
|
let largestNonMessageCardHeight = 0;
|
||||||
// contactCard.querySelector(".content").classList.add("h-100");
|
const cards = grid.querySelectorAll(".card") as NodeListOf<HTMLElement>;
|
||||||
} else if (!statusCard.classList.contains("unfocused")) {
|
for (let i = 0; i < cards.length; i++) {
|
||||||
setBestRowSpan(passwordCard, true);
|
if (cards[i].id == "card-message") continue;
|
||||||
|
if (computeRealHeight(cards[i]) > largestNonMessageCardHeight) {
|
||||||
|
largestNonMessageCardHeight = computeRealHeight(cards[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let rowSpan = Math.ceil(computeRealHeight(messageCard) / largestNonMessageCardHeight);
|
||||||
|
|
||||||
|
if (rowSpan > 0)
|
||||||
|
messageCard.style.gridRow = `span ${rowSpan}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -511,37 +474,12 @@ login.onLogin = () => {
|
|||||||
document.dispatchEvent(new CustomEvent("details-reload"));
|
document.dispatchEvent(new CustomEvent("details-reload"));
|
||||||
};
|
};
|
||||||
|
|
||||||
const setBestRowSpan = (el: HTMLElement, setOnParent: boolean) => {
|
|
||||||
let largestNonMessageCardHeight = 0;
|
|
||||||
const cards = grid.querySelectorAll(".card") as NodeListOf<HTMLElement>;
|
|
||||||
for (let i = 0; i < cards.length; i++) {
|
|
||||||
if (cards[i].id == el.id) continue;
|
|
||||||
if (computeRealHeight(cards[i]) > largestNonMessageCardHeight) {
|
|
||||||
largestNonMessageCardHeight = computeRealHeight(cards[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let rowSpan = Math.ceil(computeRealHeight(el) / largestNonMessageCardHeight);
|
|
||||||
|
|
||||||
if (rowSpan > 0)
|
|
||||||
(setOnParent ? el.parentElement : el).style.gridRow = `span ${rowSpan}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const computeRealHeight = (el: HTMLElement): number => {
|
const computeRealHeight = (el: HTMLElement): number => {
|
||||||
let children = el.children as HTMLCollectionOf<HTMLElement>;
|
let children = el.children as HTMLCollectionOf<HTMLElement>;
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
// Cope with the contact method card expanding to fill, by counting each contact method individually
|
|
||||||
if (el.id == "card-contact" && children[i].classList.contains("content")) {
|
|
||||||
// console.log("FOUND CARD_CONTACT, OG:", total + children[i].offsetHeight);
|
|
||||||
for (let j = 0; j < children[i].children.length; j++) {
|
|
||||||
total += (children[i].children[j] as HTMLElement).offsetHeight;
|
|
||||||
}
|
|
||||||
// console.log("NEW:", total);
|
|
||||||
} else {
|
|
||||||
total += children[i].offsetHeight;
|
total += children[i].offsetHeight;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
views.go
3
views.go
@ -183,11 +183,10 @@ func (app *appContext) MyUserPage(gc *gin.Context) {
|
|||||||
"notifications": notificationsEnabled,
|
"notifications": notificationsEnabled,
|
||||||
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
||||||
"strings": app.storage.lang.User[lang].Strings,
|
"strings": app.storage.lang.User[lang].Strings,
|
||||||
"validationStrings": app.storage.lang.User[lang].validationStringsJSON,
|
"validationStrings": app.storage.lang.User[lang].ValidationStrings,
|
||||||
"language": app.storage.lang.User[lang].JSON,
|
"language": app.storage.lang.User[lang].JSON,
|
||||||
"langName": lang,
|
"langName": lang,
|
||||||
"jfLink": app.config.Section("ui").Key("redirect_url").String(),
|
"jfLink": app.config.Section("ui").Key("redirect_url").String(),
|
||||||
"requirements": app.validator.getCriteria(),
|
|
||||||
}
|
}
|
||||||
if telegramEnabled {
|
if telegramEnabled {
|
||||||
data["telegramUsername"] = app.telegram.username
|
data["telegramUsername"] = app.telegram.username
|
||||||
|
Loading…
Reference in New Issue
Block a user