mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 11:43:46 +08:00
版本预发布
This commit is contained in:
@@ -37,6 +37,5 @@ func (c *cConsole) Stat(ctx context.Context, req *common.ConsoleStatReq) (res *c
|
||||
res.Volume.Rise = 40202
|
||||
res.Volume.Decline = 45003
|
||||
res.Volume.Amount = 49004
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/backend/common"
|
||||
"hotgo/internal/library/ems"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
@@ -19,14 +24,56 @@ type cEms struct{}
|
||||
|
||||
// SendTest 发送测试邮件
|
||||
func (c *cEms) SendTest(ctx context.Context, req *common.SendTestEmailReq) (res *common.SendTestEmailRes, err error) {
|
||||
err = service.SysEmsLog().Send(ctx, sysin.SendEmsInp{
|
||||
Event: consts.EmsTemplateText,
|
||||
Email: req.To,
|
||||
Content: `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="iso-8859-15">
|
||||
<title>这是一封来自HotGo的测试邮件</title>
|
||||
</head>
|
||||
<body>
|
||||
这是您通过HotGo后台发送的测试邮件。当你收到这封邮件的时候,说明已经联调成功了,恭喜你!
|
||||
</body>
|
||||
</html>`,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
conf, err := service.SysConfig().GetSmtp(ctx)
|
||||
// SendBindEms 发送换绑邮件
|
||||
func (c *cSms) SendBindEms(ctx context.Context, req *common.SendBindEmsReq) (res *common.SendBindEmsRes, err error) {
|
||||
var (
|
||||
memberId = contexts.GetUserId(ctx)
|
||||
models *entity.AdminMember
|
||||
)
|
||||
if memberId <= 0 {
|
||||
err = gerror.New("用户身份异常,请重新登录!")
|
||||
return
|
||||
}
|
||||
|
||||
err = g.Model("admin_member").
|
||||
Fields("email").
|
||||
Where("id", memberId).
|
||||
Scan(&models)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = ems.SendTestMail(conf, req.To); err != nil {
|
||||
return nil, err
|
||||
if models == nil {
|
||||
err = gerror.New("用户信息不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if models.Email == "" {
|
||||
err = gerror.New("未绑定邮箱无需发送")
|
||||
return
|
||||
}
|
||||
|
||||
err = service.SysEmsLog().Send(ctx, sysin.SendEmsInp{
|
||||
Event: consts.EmsTemplateBind,
|
||||
Email: models.Email,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (c *cSite) Captcha(ctx context.Context, req *common.LoginCaptchaReq) (res *
|
||||
func (c *cSite) Login(ctx context.Context, req *common.LoginReq) (res *common.LoginRes, err error) {
|
||||
var in adminin.MemberLoginInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -89,33 +89,23 @@ func (c *cSite) Login(ctx context.Context, req *common.LoginReq) (res *common.Lo
|
||||
|
||||
model, err := service.AdminMember().Login(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = gconv.Scan(model, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = gconv.Scan(model, &res)
|
||||
return
|
||||
}
|
||||
|
||||
// Logout 注销登录
|
||||
func (c *cSite) Logout(ctx context.Context, req *common.LoginLogoutReq) (res *common.LoginLogoutRes, err error) {
|
||||
|
||||
var authorization = jwt.GetAuthorization(ghttp.RequestFromCtx(ctx))
|
||||
|
||||
// 获取jwtToken
|
||||
jwtToken := consts.RedisJwtToken + gmd5.MustEncryptString(authorization)
|
||||
if len(jwtToken) == 0 {
|
||||
token := consts.RedisJwtToken + gmd5.MustEncryptString(jwt.GetAuthorization(ghttp.RequestFromCtx(ctx)))
|
||||
if len(token) == 0 {
|
||||
err = gerror.New("当前用户未登录!")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// 删除登录token
|
||||
ca := cache.New()
|
||||
_, err = ca.Remove(ctx, jwtToken)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
_, err = ca.Remove(ctx, token)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/backend/common"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
@@ -23,15 +28,50 @@ type cSms struct{}
|
||||
func (c *cSms) SendTest(ctx context.Context, req *common.SendTestSmsReq) (res *common.SendTestSmsRes, err error) {
|
||||
var in sysin.SendCodeInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.SysSmsLog().SendCode(ctx, in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = service.SysSmsLog().SendCode(ctx, in)
|
||||
return
|
||||
}
|
||||
|
||||
// SendBindSms 发送换绑短信
|
||||
func (c *cSms) SendBindSms(ctx context.Context, req *common.SendBindSmsReq) (res *common.SendBindSmsRes, err error) {
|
||||
var (
|
||||
memberId = contexts.GetUserId(ctx)
|
||||
models *entity.AdminMember
|
||||
)
|
||||
|
||||
if memberId <= 0 {
|
||||
err = gerror.New("用户身份异常,请重新登录!")
|
||||
return
|
||||
}
|
||||
|
||||
err = g.Model("admin_member").
|
||||
Fields("mobile").
|
||||
Where("id", memberId).
|
||||
Scan(&models)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if models == nil {
|
||||
err = gerror.New("用户信息不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if models.Mobile == "" {
|
||||
err = gerror.New("未绑定手机号无需发送")
|
||||
return
|
||||
}
|
||||
|
||||
err = service.SysSmsLog().SendCode(ctx, sysin.SendCodeInp{
|
||||
Event: consts.SmsTemplateBind,
|
||||
Mobile: models.Mobile,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,34 +20,22 @@ type cUpload struct{}
|
||||
|
||||
// UploadImage 上传图片
|
||||
func (c *cUpload) UploadImage(ctx context.Context, req *common.UploadImageReq) (res common.UploadImageRes, err error) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
file := r.GetUploadFile("file")
|
||||
file := g.RequestFromCtx(ctx).GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
res, err = service.CommonUpload().UploadImage(ctx, file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
return service.CommonUpload().UploadImage(ctx, file)
|
||||
}
|
||||
|
||||
// UploadFile 上传附件
|
||||
func (c *cUpload) UploadFile(ctx context.Context, req *common.UploadFileReq) (res common.UploadFileRes, err error) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
file := r.GetUploadFile("file")
|
||||
file := g.RequestFromCtx(ctx).GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
res, err = service.CommonUpload().UploadFile(ctx, file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
return service.CommonUpload().UploadFile(ctx, file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user