Merge branch 'x/sqlx' into r/paopao-ce-plus

r/paopao-ce-plus
Michael Li 1 year ago
commit 4b9ce81f46
No known key found for this signature in database

@ -173,6 +173,9 @@ All notable changes to paopao-ce are documented in this file.
AllowTweetVideo: true # 是否允许视频推文
AllowUserRegister: true # 是否允许用户注册
AllowPhoneBind: true # 是否允许手机绑定
DefaultTweetMaxLength: 2000 # 推文允许输入的最大长度, 默认2000字值的范围需要查询后端支持的最大字数
TweetWebEllipsisSize: 400 # Web端推文作为feed显示的最长字数默认400字
TweetMobileEllipsisSize: 300 # 移动端推文作为feed显示的最长字数默认300字
DefaultTweetVisibility: friend # 推文可见性,默认好友可见 值: public/following/friend/private
DefaultMsgLoopInterval: 5000 # 拉取未读消息的间隔,单位:毫秒, 默认5000ms
CopyrightTop: "2023 paopao.info"

@ -5,6 +5,8 @@
package jinzhu
import (
"time"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
@ -71,6 +73,7 @@ func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) (err error
UserId: userId,
}
}
metric.LatestTrendsOn = time.Now().Unix()
switch action {
case cs.MetricActionCreateTweet:
metric.TweetsCount++

@ -27,7 +27,7 @@ func (s *trendsSrvA) GetIndexTrends(userId int64, limit int, offset int) (res []
if offset >= 0 && limit > 0 {
db = db.Limit(limit).Offset(offset)
}
if err = db.Order("r.style ASC").Select("username", "nickname", "avatar").Find(&res).Error; err == nil {
if err = db.Order("r.style ASC, m.latest_trends_on DESC").Select("username", "nickname", "avatar").Find(&res).Error; err == nil {
res = cs.DistinctTrends(res)
}
return

@ -10,7 +10,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/pkg/app"
"github.com/rocboss/paopao-ce/pkg/xerror"
)
@ -41,7 +40,7 @@ func JWT() gin.HandlerFunc {
// 加载用户信息
if user, err := ums.GetUserByID(claims.UID); err == nil {
// 强制下线机制
if (conf.JWTSetting.Issuer + ":" + user.Salt) == claims.Issuer {
if app.IssuerFrom(user.Salt) == claims.Issuer {
c.Set("USER", user)
c.Set("UID", claims.UID)
c.Set("USERNAME", claims.Username)
@ -133,7 +132,7 @@ func JwtLoose() gin.HandlerFunc {
if claims, err := app.ParseToken(token); err == nil {
// 加载用户信息
user, err := ums.GetUserByID(claims.UID)
if err == nil && (conf.JWTSetting.Issuer+":"+user.Salt) == claims.Issuer {
if err == nil && app.IssuerFrom(user.Salt) == claims.Issuer {
c.Set("UID", claims.UID)
c.Set("USERNAME", claims.Username)
c.Set("USER", user)

@ -5,6 +5,8 @@
package app
import (
"crypto/md5"
"encoding/hex"
"time"
"github.com/golang-jwt/jwt/v5"
@ -22,14 +24,14 @@ func GetJWTSecret() []byte {
return []byte(conf.JWTSetting.Secret)
}
func GenerateToken(User *ms.User) (string, error) {
func GenerateToken(user *ms.User) (string, error) {
expireTime := time.Now().Add(conf.JWTSetting.Expire)
claims := Claims{
UID: User.ID,
Username: User.Username,
UID: user.ID,
Username: user.Username,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(expireTime),
Issuer: conf.JWTSetting.Issuer + ":" + User.Salt,
Issuer: IssuerFrom(user.Salt),
},
}
@ -50,3 +52,11 @@ func ParseToken(token string) (res *Claims, err error) {
}
return
}
func IssuerFrom(data string) string {
contents := make([]byte, 0, len(conf.JWTSetting.Issuer)+len(data))
copy(contents, []byte(conf.JWTSetting.Issuer))
contents = append(contents, []byte(data)...)
res := md5.Sum(contents)
return hex.EncodeToString(res[:])
}

Loading…
Cancel
Save