Skip to content

Commit

Permalink
后端代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
1303-yzym committed Jun 17, 2024
1 parent e933824 commit ea7d2d1
Show file tree
Hide file tree
Showing 33 changed files with 176 additions and 365 deletions.
2 changes: 0 additions & 2 deletions backend/api/user/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/api/user/v1/user_get_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import "github.com/gogf/gf/v2/frame/g"

type GetKeyReq struct {
g.Meta `path:"/user/get-key" method:"post" tags:"UserService" summary:"Get ETH key"`
g.Meta `path:"/user/get_key" method:"post" tags:"UserService" summary:"Get ETH key"`
Passport string `v:"required|length:0,320"`
Share string
}
Expand Down
4 changes: 2 additions & 2 deletions backend/api/user/v1/user_get_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package v1
import "github.com/gogf/gf/v2/frame/g"

type GetShareReq struct {
g.Meta `path:"/user/get-share" method:"get" tags:"UserService" summary:"get-share 获取秘钥分片"`
// Passport string `v:"required"`
g.Meta `path:"/user/get_share" method:"post" tags:"UserService" summary:"get-share 获取秘密分片"`
Passport string `v:"required"`
}
type GetShareRes struct {
Share string `v:"length:32"`
Expand Down
1 change: 0 additions & 1 deletion backend/api/user/v1/user_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ type RegisterReq struct {
}

type RegisterRes struct {
OK bool
}
4 changes: 1 addition & 3 deletions backend/api/user/v1/user_reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ type ResetPasswordReq struct {
Password string `v:"required|length:6,16"`
Password2 string `v:"required|length:6,16|same:Password"`
}
type ResetPasswordRes struct {
OK bool
}
type ResetPasswordRes struct{}
2 changes: 1 addition & 1 deletion backend/api/user/v1/user_send_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1
import "github.com/gogf/gf/v2/frame/g"

type SendKeyReq struct {
g.Meta `path:"/user/send-key" method:"post" tags:"UserService" summary:"send-key 发送密钥"`
g.Meta `path:"/user/send_key" method:"post" tags:"UserService" summary:"发送密钥 send-key"`
Passport string `v:"required|length:0,320"`
Key string `v:"required|length:32,32"`
}
Expand Down
11 changes: 0 additions & 11 deletions backend/api/user/v1/user_send_share.go

This file was deleted.

4 changes: 1 addition & 3 deletions backend/api/user/v1/user_sign_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ type SignUpReq struct {
Password2 string `v:"required|length:6,16|same:Password"`
Nickname string
}
type SignUpRes struct {
OK bool
}
type SignUpRes struct{}
11 changes: 0 additions & 11 deletions backend/api/user/v1/user_social_recovery.go

This file was deleted.

6 changes: 0 additions & 6 deletions backend/internal/consts/const_email.go

This file was deleted.

3 changes: 0 additions & 3 deletions backend/internal/consts/consts_sss.go

This file was deleted.

9 changes: 2 additions & 7 deletions backend/internal/controller/user/user_get_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"context"
v1 "github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/dao"
"github.com/gogf/gf-demo-user/v2/internal/model"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf-demo-user/v2/internal/utils/sss"
)

func (c *ControllerV1) GetKey(ctx context.Context, req *v1.GetKeyReq) (res *v1.GetKeyRes, err error) {
Expand All @@ -18,13 +17,9 @@ func (c *ControllerV1) GetKey(ctx context.Context, req *v1.GetKeyReq) (res *v1.G
shareByte,
[]byte(shareBack),
}
key, _ := service.SSS().Decrypt(ctx, model.DecryptInput{
Shares: shares,
N: 2,
})

res = &v1.GetKeyRes{
Key: string(key),
Key: string(sss.Decrypt(shares, 2)),
}

return
Expand Down
19 changes: 0 additions & 19 deletions backend/internal/controller/user/user_get_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,8 @@ package user
import (
"context"
v1 "github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/dao"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf/v2/errors/gerror"
)

func (c *ControllerV1) GetShare(ctx context.Context, req *v1.GetShareReq) (res *v1.GetShareRes, err error) {
// TODO 将后端存储的分片返回给前端
// 获取当前用户
passport := service.Session().GetUser(ctx).Passport
// 获取当前用户的分享
md := dao.Shares.Ctx(ctx)
data, err := md.Where("passport", passport).All()
if len(data) == 0 {
err = gerror.New("have no share")
return
}
// r := g.RequestFromCtx(ctx)
// r.Response.WriteJson(data)
res = &v1.GetShareRes{
Share: data[0]["share"].String(),
}

return
}
19 changes: 3 additions & 16 deletions backend/internal/controller/user/user_reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"fmt"
"github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/consts"
"github.com/gogf/gf-demo-user/v2/internal/dao"
"github.com/gogf/gf-demo-user/v2/internal/model"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf-demo-user/v2/internal/utils/email"
"github.com/gogf/gf-demo-user/v2/internal/utils/verification"
"github.com/gogf/gf/v2/errors/gerror"
)
Expand All @@ -29,19 +27,8 @@ func (c *ControllerV1) ResetPassword(ctx context.Context, req *v1.ResetPasswordR
}
fmt.Println("验证码:", code)
fmt.Println(req.Passport)
err = service.Email().SendEmail(ctx, model.EmailSendInput{
From: consts.From,
Password: consts.Password,
To: req.Passport,
Subject: "重置密码验证",
Body: "您的验证码为:\n" + code,
})
if err != nil {
return
}
res = &v1.ResetPasswordRes{
OK: true,
}
email.SendMail("重置密码验证码", "您的验证码是:\n"+code, req.Passport)
// 不存在则返回错误
return

}
9 changes: 2 additions & 7 deletions backend/internal/controller/user/user_send_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ import (
"context"
v1 "github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/dao"
"github.com/gogf/gf-demo-user/v2/internal/model"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf-demo-user/v2/internal/utils/sss"
"github.com/gogf/gf/v2/frame/g"
)

func (c *ControllerV1) SendKey(cxt context.Context, req *v1.SendKeyReq) (res *v1.SendKeyRes, err error) {

keyBytes := []byte(req.Key)
shares, _ := service.SSS().Encrypt(cxt, model.EncryptInput{
Secret: keyBytes,
N: 2,
Num: 3,
})
shares := sss.Encrypt(keyBytes, 2, 3)
sharesStr := []string{
string(shares[0]),
string(shares[1]),
Expand Down
14 changes: 0 additions & 14 deletions backend/internal/controller/user/user_send_share.go

This file was deleted.

11 changes: 0 additions & 11 deletions backend/internal/controller/user/user_social_recovery.go

This file was deleted.

1 change: 1 addition & 0 deletions backend/internal/controller/user/user_v1_is_signed_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package user

import (
"context"

"github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/service"
)
Expand Down
4 changes: 0 additions & 4 deletions backend/internal/controller/user/user_v1_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func (c *ControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *
})
} else {
err = gerror.New("验证码错误")
return
}
res = &v1.RegisterRes{
OK: true,
}
return
}
17 changes: 1 addition & 16 deletions backend/internal/controller/user/user_v1_sign_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import (
"context"
"fmt"
"github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/consts"
"github.com/gogf/gf-demo-user/v2/internal/dao"
"github.com/gogf/gf-demo-user/v2/internal/model"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf-demo-user/v2/internal/utils/verification"
"github.com/gogf/gf/v2/errors/gerror"
)
Expand All @@ -30,18 +27,6 @@ func (c *ControllerV1) SignUp(ctx context.Context, req *v1.SignUpReq) (res *v1.S
fmt.Println("验证码:", code)
fmt.Println(req.Passport)
//发送验证邮件
err = service.Email().SendEmail(ctx, model.EmailSendInput{
From: consts.From,
Password: consts.Password,
To: req.Passport,
Subject: "邮箱验证码",
Body: "您的验证码为:\n" + code,
})
if err != nil {
return
}
res = &v1.SignUpRes{
OK: true,
}
//err = email.SendMail("邮箱验证码", "您的验证码为:\n"+code, req.Passport)
return
}
50 changes: 0 additions & 50 deletions backend/internal/logic/email/email.go

This file was deleted.

2 changes: 0 additions & 2 deletions backend/internal/logic/logic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea7d2d1

Please sign in to comment.