Files
MeBox/internal/handler/auth_cookie.go
T
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

56 lines
1.3 KiB
Go

package handler
import (
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/truewhile/MeBox/internal/middleware"
"github.com/truewhile/MeBox/internal/service"
)
func setAccessTokenCookie(c *gin.Context, token string, maxAgeSeconds int) {
token = strings.TrimSpace(token)
if token == "" {
return
}
if maxAgeSeconds <= 0 {
maxAgeSeconds = int(service.AccessTokenDuration.Seconds())
}
writeAccessTokenCookie(c, token, maxAgeSeconds)
}
func clearAccessTokenCookie(c *gin.Context) {
writeAccessTokenCookie(c, "", -1)
}
func writeAccessTokenCookie(c *gin.Context, value string, maxAgeSeconds int) {
cookie := &http.Cookie{
Name: middleware.AccessTokenCookieName,
Value: value,
Path: middleware.AccessTokenCookiePath,
MaxAge: maxAgeSeconds,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
Secure: requestIsHTTPS(c),
}
if maxAgeSeconds > 0 {
cookie.Expires = time.Now().Add(time.Duration(maxAgeSeconds) * time.Second)
} else if maxAgeSeconds < 0 {
cookie.Expires = time.Unix(0, 0)
}
http.SetCookie(c.Writer, cookie)
}
func requestIsHTTPS(c *gin.Context) bool {
if c == nil || c.Request == nil {
return false
}
if c.Request.TLS != nil {
return true
}
return strings.EqualFold(c.GetHeader("X-Forwarded-Proto"), "https")
}