service/app/mix/controller/login_op.go

111 lines
2.8 KiB
Go

package controller
import (
"service/api/errcode"
loginproto "service/api/proto/login/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/mediafiller"
"github.com/gin-gonic/gin"
)
func OpLoginByPswd(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpLoginByPswdReq)
isEnabled, token, accountVO, ec := service.DefaultService.OpLoginByPswd(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLoginByPswd fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
//填充媒体切片
mediafiller.FillEntity(ctx, accountVO.Avatar)
ReplyOk(ctx, &loginproto.OpLoginData{
IsEnabled: isEnabled,
Token: token,
AccountVO: accountVO,
})
}
func OpSetPassword(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpSetPswdReq)
ec := service.DefaultService.OpSetPassword(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpSetPassword fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, &loginproto.OpSetPswdData{
OpResult: true,
})
}
func OpResetPassword(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpResetPswdReq)
ec := service.DefaultService.OpResetPassword(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLoginByVeriCode fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, &loginproto.OpResetPswdData{
OpResult: true,
})
}
func OpUpdatePassword(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpUpdatePswdReq)
ec := service.DefaultService.OpUpdatePassword(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLoginByVeriCode fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, &loginproto.OpUpdatePswdData{
OpResult: true,
})
}
func OpLoginByVeriCode(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpLoginByVeriCodeReq)
isEnabled, token, accountVO, ec := service.DefaultService.OpLoginByVeriCode(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLoginByVeriCode fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
//填充媒体切片
mediafiller.FillEntity(ctx, accountVO.Avatar)
ReplyOk(ctx, &loginproto.OpLoginData{
IsEnabled: isEnabled,
Token: token,
AccountVO: accountVO,
})
}
func OpLogout(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*loginproto.OpLogoutReq)
logoutData, ec := service.DefaultService.OpLogout(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLogout fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, logoutData)
}
func OpValidate(ctx *gin.Context) {
ReplyOk(ctx, nil)
}