Files
rootandClaude Opus 4.7 e7179da072 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>
2026-10-16 12:59:14 +08:00

85 lines
2.6 KiB
Go

package authapi
import (
"hkdj-web-server/app/service/authser"
"hkdj-web-server/pub/common"
"hkdj-web-server/pub/common/srvdef"
"hkdj-web-server/pub/common/useragent"
"hkdj-web-server/pub/pubdef"
"github.com/gin-gonic/gin"
)
func requestUA(ctx *gin.Context) useragent.UA {
ua, _ := common.GetUA(ctx)
return ua
}
type updateProfileReq struct {
NickName *string `json:"nickName"` // 新昵称(可选)
Avatar *string `json:"avatar"` // 新头像 URL(可选)
Introduction *string `json:"introduction"` // 简介(可选)
PrivacyMode *bool `json:"privacyMode"` // 隐私模式:true-开启,false-关闭(可选)
}
// UpdateProfile 修改用户资料
// @Tags 用户认证
// @Summary 修改用户资料(昵称 / 头像 / 简介 / 隐私模式,可任意组合)
// @Description 按请求头 X-User-Agent 中的 devID 识别用户;nickName、avatar、introduction、privacyMode 均为可选,至少提供一项。
// @Accept json
// @Produce json
// @Param param body updateProfileReq true "修改资料参数"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/auth/profile [POST]
func UpdateProfile(ctx *gin.Context) {
var req updateProfileReq
if err := ctx.ShouldBind(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId := common.GetUserId(ctx)
if userId <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "请先登录")
return
}
serr := authser.UpdateProfile(ctx, &authser.UpdateProfileReq{
UserId: userId,
NickName: req.NickName,
Avatar: req.Avatar,
Introduction: req.Introduction,
PrivacyMode: req.PrivacyMode,
})
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
// GetInfo 获取当前用户信息
// @Tags 用户认证
// @Summary 获取当前用户信息
// @Description 按请求头 X-User-Agent 中的 devID 识别用户,返回最新用户信息,包含金币余额、VIP状态等
// @Produce json
// @Success 200 {object} authser.LoginResp "用户信息"
// @Failure 400 {string} string "失败"
// @Router /api/app/auth/getInfo [GET]
func GetInfo(ctx *gin.Context) {
userId := common.GetUserId(ctx)
if pubdef.IsCrawlerUser(userId) {
common.ServerJSON(ctx, srvdef.Success, authser.CrawlerLoginResp())
return
}
if userId <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "请先登录")
return
}
resp, serr := authser.GetInfo(ctx, userId, requestUA(ctx))
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}