up
This commit is contained in:
+18
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user