Force relogin after webui data changes

- Add a force_relogin flag to user_pref
- Return 404 for main.php requests when the user must reauthenticate
- Clear the relogin flag after successful client login
- Mark users for relogin after webui card import, accessory changes, and profile updates

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-06-13 11:29:57 +08:00
parent 6264523c76
commit 4b2c005222
6 changed files with 74 additions and 11 deletions
+9 -11
View File
@@ -11,16 +11,6 @@ import (
"github.com/gin-gonic/gin"
)
func CheckErr(ctx *gin.Context, err error) bool {
if err != nil {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"code": 20001,
"message": err.Error(),
})
}
return err != nil
}
func Common(ctx *gin.Context) {
reqData := ""
if form, err := ctx.MultipartForm(); err == nil {
@@ -39,9 +29,17 @@ func Common(ctx *gin.Context) {
ss := session.Attach(ctx)
ctx.Set("session", ss)
if ctx.Request.URL.Path != "/login/authkey" && ctx.Request.URL.Path != "/login/login" {
if ss.UserPref.ForceRelogin {
ctx.AbortWithStatus(http.StatusNotFound)
return
}
}
authorize := ctx.GetHeader("Authorize")
params, err := url.ParseQuery(authorize)
if CheckErr(ctx, err) {
if err != nil {
ctx.AbortWithStatus(http.StatusNotFound)
return
}