up
This commit is contained in:
+18
-1
@@ -97,6 +97,23 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
|
|||||||
return
|
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
|
var publishedAt *time.Time
|
||||||
if status == models.ArticlePublished {
|
if status == models.ArticlePublished {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -104,7 +121,7 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
article := models.Article{
|
article := models.Article{
|
||||||
AuthorID: uint(userID.(int)),
|
AuthorID: authorID,
|
||||||
Title: title,
|
Title: title,
|
||||||
Slug: slug,
|
Slug: slug,
|
||||||
Summary: summary,
|
Summary: summary,
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ var translations = map[Lang]map[string]string{
|
|||||||
"dash_users": "Users",
|
"dash_users": "Users",
|
||||||
"dash_mgmt_title": "Blog Management",
|
"dash_mgmt_title": "Blog Management",
|
||||||
"dash_mgmt_desc": "Post management, categories, and settings will appear here in future updates.",
|
"dash_mgmt_desc": "Post management, categories, and settings will appear here in future updates.",
|
||||||
|
"dash_new_article": "New Article",
|
||||||
"dash_page_title": "Dashboard",
|
"dash_page_title": "Dashboard",
|
||||||
|
|
||||||
// Footer
|
// Footer
|
||||||
@@ -154,6 +155,7 @@ var translations = map[Lang]map[string]string{
|
|||||||
"dash_users": "用户",
|
"dash_users": "用户",
|
||||||
"dash_mgmt_title": "博客管理",
|
"dash_mgmt_title": "博客管理",
|
||||||
"dash_mgmt_desc": "文章管理、分类和设置将在后续版本中添加。",
|
"dash_mgmt_desc": "文章管理、分类和设置将在后续版本中添加。",
|
||||||
|
"dash_new_article": "新建文章",
|
||||||
"dash_page_title": "后台管理",
|
"dash_page_title": "后台管理",
|
||||||
|
|
||||||
// 页脚
|
// 页脚
|
||||||
|
|||||||
@@ -35,7 +35,14 @@
|
|||||||
<!-- Placeholder for future features -->
|
<!-- Placeholder for future features -->
|
||||||
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-8 text-center">
|
<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>
|
<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>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
|
|||||||
Reference in New Issue
Block a user