🎨 优化用户登录接口&优化登录日志接口
This commit is contained in:
@@ -174,7 +174,7 @@ func (a *UserApi) UpdateTeacherApplyStatus(context *gin.Context) {
|
|||||||
|
|
||||||
// GetLoginLog 获取用户登录日志
|
// GetLoginLog 获取用户登录日志
|
||||||
func (a *UserApi) GetLoginLog(context *gin.Context) {
|
func (a *UserApi) GetLoginLog(context *gin.Context) {
|
||||||
var p request.GetUserListReq
|
var p request.GetUserLoginLog
|
||||||
if err := context.ShouldBind(&p); err != nil {
|
if err := context.ShouldBind(&p); err != nil {
|
||||||
global.GVA_LOG.Error("参数错误,获取登录日志失败", zap.Error(err))
|
global.GVA_LOG.Error("参数错误,获取登录日志失败", zap.Error(err))
|
||||||
r.FailWithMessage("参数错误,获取登录日志失败", context)
|
r.FailWithMessage("参数错误,获取登录日志失败", context)
|
||||||
|
|||||||
@@ -96,3 +96,10 @@ type SetTeacherInfo struct {
|
|||||||
ExpectRate int `json:"expect_rate" form:"expect_rate"`
|
ExpectRate int `json:"expect_rate" form:"expect_rate"`
|
||||||
Weight int `json:"weight" form:"weight" `
|
Weight int `json:"weight" form:"weight" `
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetUserLoginLog struct {
|
||||||
|
request.PageInfo
|
||||||
|
UserId uint `json:"user_id" form:"user_id"`
|
||||||
|
UserName string `json:"user_name" form:"user_name"`
|
||||||
|
Ip string `json:"ip" form:"ip"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ func (u *AppUserService) Login(req request.CodeLoginReq) (users user.User, err e
|
|||||||
func (u *AppUserService) WechatLogin(info *providers.User) (users user.User, err error) {
|
func (u *AppUserService) WechatLogin(info *providers.User) (users user.User, err error) {
|
||||||
openID := info.GetOpenID()
|
openID := info.GetOpenID()
|
||||||
var count int64
|
var count int64
|
||||||
|
if openID == "" {
|
||||||
|
err = fmt.Errorf("获取用户信息失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
// 1. 判断用户是否存在
|
// 1. 判断用户是否存在
|
||||||
err = global.GVA_DB.Model(&users).Where("open_id = ?", openID).Count(&count).Error
|
err = global.GVA_DB.Model(&users).Where("open_id = ?", openID).Count(&count).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ func (u *UserService) SetUserVip(p request.SetUserVipReq) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLoginLog 获取登录日志
|
// GetLoginLog 获取登录日志
|
||||||
func (u *UserService) GetLoginLog(p request.GetUserListReq) (list []user.LoginLog, total int64, err error) {
|
func (u *UserService) GetLoginLog(p request.GetUserLoginLog) (list []user.LoginLog, total int64, err error) {
|
||||||
limit := p.PageSize
|
limit := p.PageSize
|
||||||
offset := (p.Page - 1) * p.PageSize
|
offset := (p.Page - 1) * p.PageSize
|
||||||
db := global.GVA_DB.Model(&user.LoginLog{})
|
db := global.GVA_DB.Model(&user.LoginLog{})
|
||||||
@@ -305,8 +305,12 @@ func (u *UserService) GetLoginLog(p request.GetUserListReq) (list []user.LoginLo
|
|||||||
if p.UserId != 0 {
|
if p.UserId != 0 {
|
||||||
db = db.Where("user_id = ?", p.UserId)
|
db = db.Where("user_id = ?", p.UserId)
|
||||||
}
|
}
|
||||||
if p.Name != "" {
|
if p.UserName != "" {
|
||||||
db = db.Where("user_name LIKE ?", "%"+p.Name+"%")
|
db = db.Where("user_name LIKE ?", "%"+p.UserName+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Ip != "" {
|
||||||
|
db = db.Where("ip LIKE ?", "%"+p.Ip+"%")
|
||||||
}
|
}
|
||||||
err = db.Count(&total).Error
|
err = db.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func InitWeOfficial() {
|
|||||||
|
|
||||||
func GetUserInfo(code string) *providers.User {
|
func GetUserInfo(code string) *providers.User {
|
||||||
userFromCode, err := WeOfficial.OAuth.UserFromCode(code)
|
userFromCode, err := WeOfficial.OAuth.UserFromCode(code)
|
||||||
|
//fromCode, err := WeOfficial.OAuth.TokenFromCode(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("通过code获取微信用户信息失败", zap.Error(err))
|
global.GVA_LOG.Error("通过code获取微信用户信息失败", zap.Error(err))
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user