Features: - Custom navigation links management in admin settings - Multi-language support for navigation links (Chinese/English) - Control link behavior (open in new window) - Sort order and enable/disable toggle for nav links - User registration system with validation - Admin can enable/disable user registration - Registration form with username, display name, email, password - Link to registration from login page Navigation Links: - Admin interface to add/edit/delete custom nav links - Support for both internal and external URLs - Display links in header navigation bar - Respects language preference User Registration: - Username validation (3-32 characters, alphanumeric + underscore/dash) - Password validation (minimum 6 characters) - Password confirmation matching - Optional display name and email fields - Can be toggled on/off by admin in site settings Templates: - Added navigation links settings page - Added user registration page - Updated login page with registration link - Updated base layout to render custom nav links Documentation: - NAV_LINKS_FEATURE.md - Navigation links feature documentation - REGISTRATION_FEATURE.md - User registration documentation - IMPLEMENTATION_SUMMARY.md - Overall implementation summary Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// DefaultData builds a base gin.H map populated with values set by the
|
|
// SetUserContext middleware (translations, language, auth state). Handlers
|
|
// add page-specific fields on top and pass it to c.HTML().
|
|
func DefaultData(c *gin.Context) gin.H {
|
|
tr, _ := c.Get("tr")
|
|
isLoggedIn, _ := c.Get("is_logged_in")
|
|
username, _ := c.Get("username")
|
|
lang, _ := c.Get("lang")
|
|
switchLang, _ := c.Get("switch_lang")
|
|
avatar, _ := c.Get("avatar")
|
|
displayName, _ := c.Get("display_name")
|
|
role, _ := c.Get("role")
|
|
siteSetting, _ := c.Get("site_setting")
|
|
siteLogo, _ := c.Get("site_logo")
|
|
siteLogoIsURL, _ := c.Get("site_logo_is_url")
|
|
siteFavicon, _ := c.Get("site_favicon")
|
|
siteFaviconIsURL, _ := c.Get("site_favicon_is_url")
|
|
siteLogoText, _ := c.Get("site_logo_text")
|
|
siteHeaderText, _ := c.Get("site_header_text")
|
|
siteHomeWelcome, _ := c.Get("site_home_welcome")
|
|
siteHomeSubtitle, _ := c.Get("site_home_subtitle")
|
|
siteFooterText, _ := c.Get("site_footer_text")
|
|
navLinks, _ := c.Get("nav_links")
|
|
|
|
return gin.H{
|
|
"Tr": tr,
|
|
"IsLoggedIn": isLoggedIn,
|
|
"Username": username,
|
|
"Lang": lang,
|
|
"SwitchLang": switchLang,
|
|
"Avatar": avatar,
|
|
"DisplayName": displayName,
|
|
"Role": role,
|
|
"SiteSetting": siteSetting,
|
|
"SiteLogo": siteLogo,
|
|
"SiteLogoIsURL": siteLogoIsURL,
|
|
"SiteFavicon": siteFavicon,
|
|
"SiteFaviconIsURL": siteFaviconIsURL,
|
|
"SiteLogoText": siteLogoText,
|
|
"SiteHeaderText": siteHeaderText,
|
|
"SiteHomeWelcome": siteHomeWelcome,
|
|
"SiteHomeSubtitle": siteHomeSubtitle,
|
|
"SiteFooterText": siteFooterText,
|
|
"NavLinks": navLinks,
|
|
}
|
|
}
|
|
|
|
// getTr is a convenience helper that returns the translation map from the
|
|
// Gin context, falling back to an empty map if not set.
|
|
func getTr(c *gin.Context) map[string]string {
|
|
tr, ok := c.Get("tr")
|
|
if !ok {
|
|
return map[string]string{}
|
|
}
|
|
m, ok := tr.(map[string]string)
|
|
if !ok {
|
|
return map[string]string{}
|
|
}
|
|
return m
|
|
}
|