diff --git a/api/comment_api/comment.go b/api/comment_api/comment.go new file mode 100644 index 0000000..adebab8 --- /dev/null +++ b/api/comment_api/comment.go @@ -0,0 +1,3 @@ +package comment_api + +type CommentAPI struct{} diff --git a/api/comment_api/comment_api.go b/api/comment_api/comment_api.go new file mode 100644 index 0000000..a30dc1b --- /dev/null +++ b/api/comment_api/comment_api.go @@ -0,0 +1 @@ +package comment_api diff --git a/api/oauth_api/oauth.go b/api/oauth_api/oauth.go index b4bb496..796c156 100644 --- a/api/oauth_api/oauth.go +++ b/api/oauth_api/oauth.go @@ -122,7 +122,6 @@ func HandelUserLogin(userId string) (bool, map[string]interface{}) { "data": data, "success": true, } - global.DB.Set("user_id", userId) return true, responseData } diff --git a/api/user_api/user_api.go b/api/user_api/user_api.go index 4c1dce2..92c9308 100644 --- a/api/user_api/user_api.go +++ b/api/user_api/user_api.go @@ -344,7 +344,6 @@ func handelUserLogin(user model.ScaAuthUser, autoLogin bool, c *gin.Context) { result.FailWithMessage(ginI18n.MustGetMessage(c, "LoginFailed"), c) return } - global.DB.Set("user_id", user.UID) result.OkWithData(data, c) } diff --git a/middleware/security_headers.go b/middleware/security_headers.go index 5774d7a..a838b33 100644 --- a/middleware/security_headers.go +++ b/middleware/security_headers.go @@ -1,22 +1,18 @@ package middleware import ( - ginI18n "github.com/gin-contrib/i18n" "github.com/gin-gonic/gin" - "schisandra-cloud-album/common/result" - "schisandra-cloud-album/global" - "strings" ) func SecurityHeaders() gin.HandlerFunc { return func(c *gin.Context) { - url := strings.TrimPrefix(global.CONFIG.System.Web, "https://") - requestHost := c.Request.Host - if requestHost != url { - result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c) - c.Abort() - return - } + //url := strings.TrimPrefix(global.CONFIG.System.Web, "https://") + //requestHost := c.Request.Host + //if requestHost != url { + // result.FailWithMessage(ginI18n.MustGetMessage(c, "IllegalRequests"), c) + // c.Abort() + // return + //} c.Header("X-Frame-Options", "DENY") c.Header("Content-Security-Policy", "default-src 'self'; connect-src *; font-src *; script-src-elem * 'unsafe-inline'; img-src * data:; style-src * 'unsafe-inline';") c.Header("X-XSS-Protection", "1; mode=block") diff --git a/model/sca_auth_casbin_rule.go b/model/sca_auth_casbin_rule.go index c37ff3a..9b62759 100644 --- a/model/sca_auth_casbin_rule.go +++ b/model/sca_auth_casbin_rule.go @@ -1,5 +1,7 @@ package model +const ScaAuthCasbinRuleTableName = "sca_auth_casbin_rule" + // ScaAuthCasbinRule 角色/权限/用户关系表 type ScaAuthCasbinRule struct { Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"` @@ -13,5 +15,5 @@ type ScaAuthCasbinRule struct { } func (m *ScaAuthCasbinRule) TableName() string { - return "sca_auth_casbin_rule" + return ScaAuthCasbinRuleTableName } diff --git a/model/sca_auth_permission.go b/model/sca_auth_permission.go index d15c72e..68c171d 100644 --- a/model/sca_auth_permission.go +++ b/model/sca_auth_permission.go @@ -2,9 +2,6 @@ package model import ( "encoding/json" - "fmt" - "gorm.io/gorm" - "schisandra-cloud-album/global" "time" ) @@ -42,36 +39,3 @@ func (permission *ScaAuthPermission) MarshalBinary() ([]byte, error) { func (permission *ScaAuthPermission) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, permission) } -func (permission *ScaAuthPermission) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - global.LOG.Error("user_id is not in global.DB") - return fmt.Errorf("user_id is not in global.DB") - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - permission.CreatedBy = userIdStr - return nil -} - -func (permission *ScaAuthPermission) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - global.LOG.Error("user_id is not in global.DB") - return fmt.Errorf("user_id is not in global.DB") - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - permission.UpdateBy = userIdStr - return nil -} diff --git a/model/sca_auth_role.go b/model/sca_auth_role.go index 2f810a5..9036216 100644 --- a/model/sca_auth_role.go +++ b/model/sca_auth_role.go @@ -2,9 +2,6 @@ package model import ( "encoding/json" - "fmt" - "gorm.io/gorm" - "schisandra-cloud-album/global" "time" ) @@ -34,39 +31,3 @@ func (role *ScaAuthRole) MarshalBinary() ([]byte, error) { func (role *ScaAuthRole) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, role) } - -func (role *ScaAuthRole) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - creator := "system" - role.CreatedBy = &creator - return nil - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - role.CreatedBy = userIdStr - return nil -} - -func (role *ScaAuthRole) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - creator := "system" - role.CreatedBy = &creator - return nil - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - role.UpdateBy = userIdStr - return nil -} diff --git a/model/sca_auth_user.go b/model/sca_auth_user.go index b80b658..1ce7e5a 100644 --- a/model/sca_auth_user.go +++ b/model/sca_auth_user.go @@ -2,9 +2,6 @@ package model import ( "encoding/json" - "fmt" - "gorm.io/gorm" - "schisandra-cloud-album/global" "time" ) @@ -45,38 +42,3 @@ func (user *ScaAuthUser) MarshalBinary() ([]byte, error) { func (user *ScaAuthUser) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, user) } -func (user *ScaAuthUser) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - creator := "system" - user.CreatedBy = &creator - return nil - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - user.CreatedBy = userIdStr - return nil -} - -func (user *ScaAuthUser) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - creator := "system" - user.CreatedBy = &creator - return nil - } - - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - user.UpdateBy = userIdStr - return nil -} diff --git a/model/sca_auth_user_device.go b/model/sca_auth_user_device.go index c73a07a..8e1d5e7 100644 --- a/model/sca_auth_user_device.go +++ b/model/sca_auth_user_device.go @@ -1,9 +1,6 @@ package model import ( - "fmt" - "gorm.io/gorm" - "schisandra-cloud-album/global" "time" ) @@ -36,19 +33,3 @@ type ScaAuthUserDevice struct { func (*ScaAuthUserDevice) TableName() string { return TableNameScaAuthUserDevice } - -func (device *ScaAuthUserDevice) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - global.LOG.Error("user_id is not found in global.DB") - return fmt.Errorf("user_id is not found in global.DB") - } - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - - device.UpdateBy = userIdStr - return nil -} diff --git a/model/sca_auth_user_social.go b/model/sca_auth_user_social.go index bb302b2..0060305 100644 --- a/model/sca_auth_user_social.go +++ b/model/sca_auth_user_social.go @@ -1,9 +1,6 @@ package model import ( - "fmt" - "gorm.io/gorm" - "schisandra-cloud-album/global" "time" ) @@ -27,18 +24,3 @@ type ScaAuthUserSocial struct { func (*ScaAuthUserSocial) TableName() string { return TableNameScaAuthUserSocial } - -func (social *ScaAuthUserSocial) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := tx.Get("user_id") - if !b { - global.LOG.Error("user_id is not found in global.DB") - return fmt.Errorf("user_id is not found in global.DB") - } - userIdStr, ok := userId.(*string) - if !ok { - global.LOG.Error("user_id is not of type *string") - return fmt.Errorf("user_id is not of type *string") - } - social.UpdateBy = userIdStr - return nil -} diff --git a/model/sca_comment_likes.go b/model/sca_comment_likes.go index 32fd331..8c5c65f 100644 --- a/model/sca_comment_likes.go +++ b/model/sca_comment_likes.go @@ -1,5 +1,7 @@ package model +const ScaCommentLikesTableName = "sca_comment_likes" + // ScaCommentLikes 评论点赞表 type ScaCommentLikes struct { Id int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"` @@ -8,5 +10,5 @@ type ScaCommentLikes struct { } func (like *ScaCommentLikes) TableName() string { - return "sca_comment_likes" + return ScaCommentLikesTableName } diff --git a/model/sca_comment_reply.go b/model/sca_comment_reply.go index 1ebcd26..06fb586 100644 --- a/model/sca_comment_reply.go +++ b/model/sca_comment_reply.go @@ -5,31 +5,37 @@ import ( "time" ) +const ScaCommentReplyTable = "sca_comment_reply" + // ScaCommentReply 评论表 type ScaCommentReply struct { - Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"` - UserId string `gorm:"column:user_id;type:varchar(20);comment:评论用户id" json:"user_id"` - TopicId string `gorm:"column:topic_id;type:varchar(20);comment:评论话题id" json:"topic_id"` - TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"` - Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"` - CommentType int `gorm:"column:comment_type;type:int(11);comment:评论类型 0评论 1 回复" json:"comment_type"` - ReplyId string `gorm:"column:reply_id;type:varchar(20);comment:回复目标id" json:"reply_id"` - ReplyUser string `gorm:"column:reply_user;type:varchar(20);comment:回复人id" json:"reply_user"` - Username string `gorm:"column:username;type:varchar(20);comment:评论用户昵称" json:"username"` - Avatar string `gorm:"column:avatar;type:longtext;comment:评论用户头像" json:"avatar"` - Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"` - Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"` - ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"` - PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"` - CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` - UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` - Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"` - CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` - UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` + Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"` + UserId string `gorm:"column:user_id;type:varchar(20);comment:评论用户id" json:"user_id"` + TopicId string `gorm:"column:topic_id;type:varchar(20);comment:评论话题id" json:"topic_id"` + TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"` + Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"` + CommentType int `gorm:"column:comment_type;type:int(11);comment:评论类型 0评论 1 回复" json:"comment_type"` + ReplyId string `gorm:"column:reply_id;type:varchar(20);comment:回复目标id" json:"reply_id"` + ReplyUser string `gorm:"column:reply_user;type:varchar(20);comment:回复人id" json:"reply_user"` + Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"` + Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"` + ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"` + PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"` + CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` + UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` + Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"` + CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` + UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` + Dislikes int64 `gorm:"column:dislikes;type:bigint(20);comment:踩数" json:"dislikes"` + CommentIp string `gorm:"column:comment_ip;type:varchar(20);comment:评论ip" json:"comment_ip"` + Location string `gorm:"column:location;type:varchar(20);comment:评论地址" json:"location"` + Browser string `gorm:"column:browser;type:varchar(20);comment:评论浏览器" json:"browser"` + OperatingSystem string `gorm:"column:operating_system;type:varchar(20);comment:评论操作系统" json:"operating_system"` + Order int64 `gorm:"column:order;type:bigint(20);comment:评论排序" json:"order"` } func (comment *ScaCommentReply) TableName() string { - return "sca_comment_reply" + return ScaCommentReplyTable } // BeforeCreate 创建前回调 diff --git a/service/comment_likes/comment_likes.go b/service/comment_likes/comment_likes.go new file mode 100644 index 0000000..f5de04b --- /dev/null +++ b/service/comment_likes/comment_likes.go @@ -0,0 +1,3 @@ +package comment_likes + +type CommentLikes struct{} diff --git a/service/comment_likes/comment_likes_service.go b/service/comment_likes/comment_likes_service.go new file mode 100644 index 0000000..f4b5304 --- /dev/null +++ b/service/comment_likes/comment_likes_service.go @@ -0,0 +1 @@ +package comment_likes diff --git a/service/comment_reply_service/comment_reply.go b/service/comment_reply_service/comment_reply.go new file mode 100644 index 0000000..f4a5984 --- /dev/null +++ b/service/comment_reply_service/comment_reply.go @@ -0,0 +1,3 @@ +package comment_reply_service + +type CommentReplyService struct{} diff --git a/service/comment_reply_service/comment_reply_service.go b/service/comment_reply_service/comment_reply_service.go new file mode 100644 index 0000000..12fc35d --- /dev/null +++ b/service/comment_reply_service/comment_reply_service.go @@ -0,0 +1 @@ +package comment_reply_service