This commit is contained in:
2026-06-21 19:42:47 +08:00
parent a84982e1f5
commit 62732ba348
3 changed files with 28 additions and 2 deletions
+18 -1
View File
@@ -97,6 +97,23 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
return
}
// The session stores user.ID, which is a gorm uint — but be defensive
// across int / uint / int64 storage so a type mismatch never panics.
var authorID uint
switch v := userID.(type) {
case uint:
authorID = v
case int:
authorID = uint(v)
case int64:
authorID = uint(v)
case float64:
authorID = uint(v)
default:
c.Redirect(http.StatusFound, "/login")
return
}
var publishedAt *time.Time
if status == models.ArticlePublished {
now := time.Now()
@@ -104,7 +121,7 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
}
article := models.Article{
AuthorID: uint(userID.(int)),
AuthorID: authorID,
Title: title,
Slug: slug,
Summary: summary,
+2
View File
@@ -54,6 +54,7 @@ var translations = map[Lang]map[string]string{
"dash_users": "Users",
"dash_mgmt_title": "Blog Management",
"dash_mgmt_desc": "Post management, categories, and settings will appear here in future updates.",
"dash_new_article": "New Article",
"dash_page_title": "Dashboard",
// Footer
@@ -154,6 +155,7 @@ var translations = map[Lang]map[string]string{
"dash_users": "用户",
"dash_mgmt_title": "博客管理",
"dash_mgmt_desc": "文章管理、分类和设置将在后续版本中添加。",
"dash_new_article": "新建文章",
"dash_page_title": "后台管理",
// 页脚
+8 -1
View File
@@ -35,7 +35,14 @@
<!-- Placeholder for future features -->
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-8 text-center">
<h3 class="text-xl font-semibold text-gray-800 mb-2">{{index .Tr "dash_mgmt_title"}}</h3>
<p class="text-gray-500">{{index .Tr "dash_mgmt_desc"}}</p>
<p class="text-gray-500 mb-6">{{index .Tr "dash_mgmt_desc"}}</p>
<a href="/admin/articles/new"
class="inline-flex items-center gap-2 bg-blue-600 text-white px-6 py-3 rounded-lg font-medium hover:bg-blue-700 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
{{index .Tr "dash_new_article"}}
</a>
</div>
</section>
{{template "footer" .}}