Skip to content

Commit

Permalink
Merge pull request TheLastHobbit#10 from 1303-yzym/main
Browse files Browse the repository at this point in the history
完善后端功能
  • Loading branch information
TheLastHobbit authored Jun 27, 2024
2 parents 2c26cee + 1d3cb6f commit 979bf8f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
1 change: 1 addition & 0 deletions backend/api/user/user.go

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

11 changes: 11 additions & 0 deletions backend/api/user/v1/user_getmessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1

import "github.com/gogf/gf/v2/frame/g"

type GetMessageReq struct {
g.Meta `path:"/user/get-message" method:"get" tags:"UserService" summary:"get-message 用户发送邮件后,后端获取最新邮件"`
}

type GetMessageRes struct {
OK bool `dc:"若获取成功,返回true"`
}
23 changes: 23 additions & 0 deletions backend/internal/controller/user/user_getmessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package user

import (
"context"
"fmt"
v1 "github.com/gogf/gf-demo-user/v2/api/user/v1"
"github.com/gogf/gf-demo-user/v2/internal/service"
"os"
"time"
)

func (c *ControllerV1) GetMessage(cxt context.Context, req *v1.GetMessageReq) (res *v1.GetMessageRes, err error) {
// 等待邮件发送成功
time.Sleep(10 * time.Second)
// 获取邮件
service.Email().GetEmail(cxt)
content, err := os.ReadFile("text/email.txt")
// r := g.RequestFromCtx(cxt)
// r.Response.Write(content)
fmt.Println(string(content))
return

}
22 changes: 16 additions & 6 deletions backend/internal/controller/user/user_social_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ package user
import (
"context"
v1 "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/model"
"github.com/gogf/gf-demo-user/v2/internal/service"
"github.com/gogf/gf/v2/frame/g"
"os"
)

func (c *ControllerV1) SocialRecovery(cxt context.Context, req *v1.SocialRecoveryReq) (res *v1.SocialRecoveryRes, err error) {
service.Email().GetEmail(cxt)
content, err := os.ReadFile("text/email.txt")
r := g.RequestFromCtx(cxt)
r.Response.Write(content)
// 发送引导邮件
err = service.Email().SendEmail(cxt, model.EmailSendInput{
To: service.Session().GetUser(cxt).Passport,
Subject: "社交恢复",
Body: "请向此邮箱发送您的新地址,我们将帮您恢复账号。",
From: consts.From,
Password: consts.Password,
})
if err != nil {
return
}
res = &v1.SocialRecoveryRes{
OK: true,
}
return

}
26 changes: 0 additions & 26 deletions backend/internal/logic/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ func (s sEmail) SendEmail(ctx context.Context, in model.EmailSendInput) (err err
}
fmt.Println("Email sent successfully.")
return nil

/*
//由于国内IP会被谷歌服务器屏蔽,因此使用网易的服务
// SMTP服务器地址和端口号
smtpHost := "smtp.gmail.com"
smtpPort := "587"
// 设置邮件内容
message := []byte("To: " + in.To + "\r\n" +
"Subject: " + in.Subject + "\r\n" +
"\r\n" +
in.Body + "\r\n")
// 连接到SMTP服务器
auth := smtp.PlainAuth("", in.From, in.Password, smtpHost)
// 发送邮件
err = smtp.SendMail(smtpHost+":"+smtpPort, auth, in.From, []string{in.To}, message)
if err != nil {
fmt.Println("Error sending email:", err)
return err
}
fmt.Println("Email sent successfully.")
return nil
*/
}

func (s sEmail) GetEmail(ctx context.Context) (err error) {
Expand Down
Binary file removed backend/main.exe~
Binary file not shown.

0 comments on commit 979bf8f

Please sign in to comment.