Initial fork commit.
Some checks failed
Release S-UI / build-frontend (push) Failing after 1m53s
Release S-UI / build-386 (push) Has been skipped
Release S-UI / build-amd64 (push) Has been skipped
Release S-UI / build-armv5 (push) Has been skipped
Release S-UI / build-armv6 (push) Has been skipped
Release S-UI / build-armv7 (push) Has been skipped
Release S-UI / build-s390x (push) Has been skipped
Release S-UI / build-arm64 (push) Has been skipped
Build S-UI for Windows / build-frontend (push) Failing after 2s
Build S-UI for Windows / build-windows-amd64 (push) Has been skipped
Build S-UI for Windows / build-windows-arm64 (push) Has been skipped

Signed-off-by: Pavel Kirilin <s3riussan@gmail.com>
This commit is contained in:
2026-05-28 16:36:05 +02:00
commit 601931f03f
108 changed files with 15703 additions and 0 deletions

69
api/session.go Normal file
View File

@@ -0,0 +1,69 @@
package api
import (
"encoding/gob"
"github.com/alireza0/s-ui/database/model"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
const (
loginUser = "LOGIN_USER"
)
func init() {
gob.Register(model.User{})
}
func SetLoginUser(c *gin.Context, userName string, maxAge int) error {
options := sessions.Options{
Path: "/",
Secure: false,
}
if maxAge > 0 {
options.MaxAge = maxAge * 60
}
s := sessions.Default(c)
s.Set(loginUser, userName)
s.Options(options)
return s.Save()
}
func SetMaxAge(c *gin.Context) error {
s := sessions.Default(c)
s.Options(sessions.Options{
Path: "/",
})
return s.Save()
}
func GetLoginUser(c *gin.Context) string {
s := sessions.Default(c)
obj := s.Get(loginUser)
if obj == nil {
return ""
}
objStr, ok := obj.(string)
if !ok {
return ""
}
return objStr
}
func IsLogin(c *gin.Context) bool {
return GetLoginUser(c) != ""
}
func ClearSession(c *gin.Context) {
s := sessions.Default(c)
s.Clear()
s.Options(sessions.Options{
Path: "/",
MaxAge: -1,
})
s.Save()
}