feat: 同步 huangguo2-server 的 11 个非基线提交
按意图重做在 huakui 代码底: - 删除数据埋点逻辑:移除 pub/dataReport、reportser、srv_report、 eventmod、上报定时任务及注册/登录/点赞/收藏/评论/解锁/订单处的 上报调用和 reportSdkConfig 配置下发 - app 认证改为按设备ID识别用户:去掉 token 校验、Register/Login/ ResetPassword/GuestLogin 接口,新增 ResolveDeviceUser 和设备缓存 - 广告改为按 AppId 从媒资中心拉取:pub/storage 新增 QueryAdvitise, UpdateAdvitiseData 替代 UpdateAdvitiseDataFromJt - 后台登录取消谷歌二次验证,密码正确即登录 - 短剧/专题 slug 改为 10 位大小写字母+数字混合 - 本地 app.yaml/web.yaml 保留 HKDJNET_* 模板(不提交生产凭据) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+8
-156
@@ -2,13 +2,10 @@ package authapi
|
||||
|
||||
import (
|
||||
"hkdj-web-server/app/service/authser"
|
||||
"hkdj-web-server/app/service/wordsfilterser"
|
||||
"hkdj-web-server/pub/common"
|
||||
"hkdj-web-server/pub/common/ipaddr"
|
||||
"hkdj-web-server/pub/common/srvdef"
|
||||
"hkdj-web-server/pub/common/useragent"
|
||||
"hkdj-web-server/pub/pubdef"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -18,132 +15,17 @@ func requestUA(ctx *gin.Context) useragent.UA {
|
||||
return ua
|
||||
}
|
||||
|
||||
func applyRequestDevID(ua useragent.UA, devID string) useragent.UA {
|
||||
if v := strings.TrimSpace(devID); v != "" {
|
||||
ua.DevID = v
|
||||
}
|
||||
return ua
|
||||
}
|
||||
|
||||
type registerReq struct {
|
||||
AccountNo string `json:"accountNo" binding:"required"` // 账号
|
||||
Email string `json:"email" binding:"required"` // 邮箱
|
||||
Password string `json:"password" binding:"required"` // 明文密码
|
||||
AgentInviteCode string `json:"agentInviteCode"` // 邀请人的邀请码(可选)
|
||||
DevID string `json:"devID"` // 设备唯一标示(可选)
|
||||
Channel string `json:"channel"` // 渠道码(可选,用户无商区码时写入)
|
||||
}
|
||||
|
||||
type loginReq struct {
|
||||
Account string `json:"account" binding:"required"` // 账号或邮箱
|
||||
Password string `json:"password" binding:"required"` // 明文密码
|
||||
DevID string `json:"devID"` // 设备唯一标示(可选)
|
||||
Channel string `json:"channel"` // 渠道码(可选,用户无商区码时写入)
|
||||
}
|
||||
|
||||
type resetPasswordReq struct {
|
||||
AccountNo string `json:"accountNo" binding:"required"` // 账号
|
||||
Email string `json:"email" binding:"required"` // 邮箱
|
||||
NewPassword string `json:"newPassword" binding:"required"` // 新密码
|
||||
}
|
||||
|
||||
type updateProfileReq struct {
|
||||
NickName *string `json:"nickName"` // 新昵称(可选)
|
||||
Avatar *string `json:"avatar"` // 新头像 URL(可选)
|
||||
Introduction *string `json:"introduction"` // 简介(可选)
|
||||
PrivacyMode *bool `json:"privacyMode"` // 隐私模式:true-开启,false-关闭(可选)
|
||||
OldPassword *string `json:"oldPassword"` // 旧密码明文(已设置密码时修改必填)
|
||||
NewPassword *string `json:"newPassword"` // 新密码明文(设置或修改密码时必填)
|
||||
}
|
||||
|
||||
// GuestLogin 游客登录
|
||||
// @Tags 用户认证
|
||||
// @Summary 游客登录
|
||||
// @Description 按设备ID创建或找回游客账号;请求头可带 Authorization 复用已有游客会话。需传 X-User-Agent
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body authser.GuestLoginReq true "游客登录参数"
|
||||
// @Success 200 {object} authser.LoginResp "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/app/auth/guest [POST]
|
||||
func GuestLogin(ctx *gin.Context) {
|
||||
var req authser.GuestLoginReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
ua, err := common.GetUA(ctx)
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.NoUA, nil)
|
||||
return
|
||||
}
|
||||
if req.DevID == "" {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, "devID不能为空")
|
||||
return
|
||||
}
|
||||
ua.DevID = req.DevID
|
||||
resp, serr := authser.GuestLogin(ctx, common.GetUserId(ctx), ipaddr.ResolveClientIP(ctx), &req, ua)
|
||||
if serr != nil {
|
||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||
return
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// Register 用户注册
|
||||
// @Tags 用户认证
|
||||
// @Summary 注册
|
||||
// @Description 传入账号、邮箱、明文密码。请求头带游客 Authorization 时升级该游客为普通用户,否则新建用户
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body registerReq true "注册参数"
|
||||
// @Success 200 {object} authser.LoginResp "注册成功,返回 token 及用户基本信息"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/app/auth/register [POST]
|
||||
func Register(ctx *gin.Context) {
|
||||
var req registerReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
ua := applyRequestDevID(requestUA(ctx), req.DevID)
|
||||
resp, serr := authser.Register(ctx, common.GetUserId(ctx), req.AccountNo, req.Email, req.Password, req.AgentInviteCode, ua, ipaddr.ResolveClientIP(ctx), req.Channel)
|
||||
if serr != nil {
|
||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||
return
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
// @Tags 用户认证
|
||||
// @Summary 登录
|
||||
// @Description 账号或邮箱均可作为登录凭证
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body loginReq true "登录参数"
|
||||
// @Success 200 {object} authser.LoginResp "登录成功,返回 token 及用户基本信息"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/app/auth/login [POST]
|
||||
func Login(ctx *gin.Context) {
|
||||
var req loginReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
ua := applyRequestDevID(requestUA(ctx), req.DevID)
|
||||
resp, serr := authser.Login(ctx, req.Account, req.Password, ua, ipaddr.ResolveClientIP(ctx), req.Channel)
|
||||
if serr != nil {
|
||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||
return
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// UpdateProfile 修改用户资料
|
||||
// @Tags 用户认证
|
||||
// @Summary 修改用户资料(头像 / 简介 / 密码,可任意组合)
|
||||
// @Description 用户信息通过 token 获取,无需传账号;nickName、avatar、introduction、oldPassword+newPassword 均为可选,至少提供一项。未设置密码时传 newPassword 可设置密码,已设置密码时修改需传 oldPassword+newPassword
|
||||
// @Summary 修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)
|
||||
// @Description 按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode 均为可选,至少提供一项。
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body updateProfileReq true "修改资料参数"
|
||||
@@ -151,18 +33,14 @@ func Login(ctx *gin.Context) {
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/app/auth/profile [POST]
|
||||
func UpdateProfile(ctx *gin.Context) {
|
||||
userId := common.GetUserId(ctx)
|
||||
if userId <= 0 {
|
||||
common.ServerJSON(ctx, srvdef.InvalidToken, nil)
|
||||
return
|
||||
}
|
||||
var req updateProfileReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
if req.NickName != nil && !wordsfilterser.Validate(*req.NickName) {
|
||||
common.ServerJSON(ctx, srvdef.ErrContainIllegalWord, "包含非法字符")
|
||||
userId := common.GetUserId(ctx)
|
||||
if userId <= 0 {
|
||||
common.ServerJSON(ctx, srvdef.InvalidToken, "请先登录")
|
||||
return
|
||||
}
|
||||
serr := authser.UpdateProfile(ctx, &authser.UpdateProfileReq{
|
||||
@@ -171,8 +49,6 @@ func UpdateProfile(ctx *gin.Context) {
|
||||
Avatar: req.Avatar,
|
||||
Introduction: req.Introduction,
|
||||
PrivacyMode: req.PrivacyMode,
|
||||
OldPassword: req.OldPassword,
|
||||
NewPassword: req.NewPassword,
|
||||
})
|
||||
if serr != nil {
|
||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||
@@ -184,7 +60,7 @@ func UpdateProfile(ctx *gin.Context) {
|
||||
// GetInfo 获取当前用户信息
|
||||
// @Tags 用户认证
|
||||
// @Summary 获取当前用户信息
|
||||
// @Description 通过 token 获取最新用户信息,包含金币余额、VIP状态等
|
||||
// @Description 按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等
|
||||
// @Produce json
|
||||
// @Success 200 {object} authser.LoginResp "用户信息"
|
||||
// @Failure 400 {string} string "失败"
|
||||
@@ -192,11 +68,11 @@ func UpdateProfile(ctx *gin.Context) {
|
||||
func GetInfo(ctx *gin.Context) {
|
||||
userId := common.GetUserId(ctx)
|
||||
if pubdef.IsCrawlerUser(userId) {
|
||||
common.ServerJSON(ctx, srvdef.Success, authser.CrawlerLoginResp(""))
|
||||
common.ServerJSON(ctx, srvdef.Success, authser.CrawlerLoginResp())
|
||||
return
|
||||
}
|
||||
if userId <= 0 {
|
||||
common.ServerJSON(ctx, srvdef.InvalidToken, nil)
|
||||
common.ServerJSON(ctx, srvdef.InvalidToken, "请先登录")
|
||||
return
|
||||
}
|
||||
resp, serr := authser.GetInfo(ctx, userId, requestUA(ctx))
|
||||
@@ -206,27 +82,3 @@ func GetInfo(ctx *gin.Context) {
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// ResetPassword 找回密码
|
||||
// @Tags 用户认证
|
||||
// @Summary 找回密码
|
||||
// @Description 通过账号和邮箱双重校验后重置密码,两者必须同时匹配同一用户
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body resetPasswordReq true "找回密码参数"
|
||||
// @Success 200 {string} string "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/app/auth/resetPassword [POST]
|
||||
func ResetPassword(ctx *gin.Context) {
|
||||
var req resetPasswordReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
serr := authser.ResetPassword(ctx, req.AccountNo, req.Email, req.NewPassword)
|
||||
if serr != nil {
|
||||
common.ServerJSON(ctx, serr.Code, serr.Tips)
|
||||
return
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, "")
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ func Info(ctx *gin.Context) {
|
||||
SeoInfo: configser.GetSiteSeoInfo(),
|
||||
SeoNavInfo: configser.GetNavSeoInfo(),
|
||||
NavPageList: configser.GetNavPageList(),
|
||||
ReportSDKConfig: configInfo.ReportSDKConfig,
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
+2
-19
@@ -13,22 +13,5 @@ type AdsClickInfo struct {
|
||||
Location int64 `json:"location,omitempty" binding:"required"` // 位置ID
|
||||
}
|
||||
|
||||
type AdvitiseData struct {
|
||||
HomeList []proxy.AdvitiseInfo `json:"homeList" bson:"homeList"` // 首页列表
|
||||
DetailTopList []proxy.AdvitiseInfo `json:"detailTopList" bson:"detailTopList"` // 详情页顶部广告
|
||||
NineGridList []proxy.AdvitiseInfo `json:"nineGridList" bson:"nineGridList"` // 9宫格
|
||||
DetailbannerList []proxy.AdvitiseInfo `json:"detailbannerList" bson:"detailbannerList"` // 详情banner
|
||||
LaunchScreenList []proxy.AdvitiseInfo `json:"launchScreenList"` // 启动页广告
|
||||
FloatingList []proxy.AdvitiseInfo `json:"floatingList" bson:"floatingList"` // 悬浮小方块
|
||||
AList []proxy.AdvitiseInfo `json:"AList"` // 固定12广告位
|
||||
BList []proxy.AdvitiseInfo `json:"BList"` // 固定13广告位
|
||||
DialogList []proxy.AdvitiseInfo `json:"dialogList" bson:"dialogList"` // 弹窗广告
|
||||
BottomBanner []proxy.AdvitiseInfo `json:"bottomBanner" bson:"bottomBanner"` // 底部banner
|
||||
|
||||
VideoInfoList []proxy.AdvitiseInfo `json:"videoInfoList" bson:"videoInfoList"` // 视频详情
|
||||
DownList []proxy.AdvitiseInfo `json:"downList" bson:"downList"` // 底部广告
|
||||
FriendList []proxy.AdvitiseInfo `json:"friendList" bson:"friendList"` // 友链
|
||||
TitleList []proxy.AdvitiseInfo `json:"titleList" bson:"titleList"` // 标题广告
|
||||
PlayList []proxy.AdvitiseInfo `json:"playList" bson:"playList"` // 播放强制跳转
|
||||
PauseyList []proxy.AdvitiseInfo `json:"pauseyList" bson:"pauseyList"` // 暂停广告
|
||||
}
|
||||
// AdvitiseData 广告数据,直接使用媒资中心返回的结构
|
||||
type AdvitiseData = proxy.AdvitiseData
|
||||
|
||||
@@ -38,7 +38,6 @@ type ConfigInfo struct {
|
||||
DHDescription string `json:"dhDescription" bson:"dhDescription"` // 导航SEO描述
|
||||
DHSiteName string `json:"dhSiteName" bson:"dhSiteName"` // 导航SEO网站名称
|
||||
ActressBackGround string `json:"actressBackGround" bson:"actressBackGround"` // 女优通用背景图
|
||||
ReportSDKConfig string `json:"reportSdkConfig"` // 数据上报SDK域名配置
|
||||
WatermarkImage string `json:"watermarkImage"` // 图片水印文件
|
||||
CustomerServiceHost string `json:"customerServiceHost"` // 在线客服
|
||||
ChannelCode string `json:"channelCode"` // 渠道码
|
||||
@@ -66,8 +65,6 @@ type ConfigInfoResp struct {
|
||||
SeoNavInfo SeoNavInfo `json:"seoNavInfo"`
|
||||
// 导航页线路集合
|
||||
NavPageList []NavPageItem `json:"navPageList"`
|
||||
// 数据上报SDK域名配置
|
||||
ReportSDKConfig string `json:"reportSdkConfig"`
|
||||
}
|
||||
|
||||
// SeoNavInfo 导航SEO信息
|
||||
|
||||
Reference in New Issue
Block a user