feat: add update password func
This commit is contained in:
parent
da62b8f230
commit
4c8121bfdf
|
|
@ -1,8 +1,11 @@
|
||||||
package ping
|
package ping
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/internal/svc"
|
"backend/pkg/notification/domain/usecase"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"backend/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
@ -23,5 +26,16 @@ func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *PingLogic) Ping() error {
|
func (l *PingLogic) Ping() error {
|
||||||
|
|
||||||
|
err := l.svcCtx.DeliveryUC.SendEmail(l.ctx, usecase.MailReq{
|
||||||
|
To: []string{"igs170911@gmail.com"},
|
||||||
|
From: l.svcCtx.Config.SMTPConfig.Sender,
|
||||||
|
SenderName: "t",
|
||||||
|
Subject: "test",
|
||||||
|
Body: "good",
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Println(err)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"backend/internal/svc"
|
"backend/internal/svc"
|
||||||
"backend/internal/types"
|
"backend/internal/types"
|
||||||
|
errs "backend/pkg/library/errors"
|
||||||
|
mbr "backend/pkg/member/domain/member"
|
||||||
|
member "backend/pkg/member/domain/usecase"
|
||||||
|
"backend/pkg/permission/domain/token"
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
@ -24,8 +27,32 @@ func NewSubmitVerificationCodeLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *SubmitVerificationCodeLogic) SubmitVerificationCode(req *types.SubmitVerificationCodeReq) (resp *types.RespOK, err error) {
|
func (l *SubmitVerificationCodeLogic) SubmitVerificationCode(req *types.SubmitVerificationCodeReq) (*types.RespOK, error) {
|
||||||
// todo: add your logic here and delete this line
|
var ct mbr.GenerateCodeType
|
||||||
|
switch req.Purpose {
|
||||||
return
|
case "email_verification":
|
||||||
|
ct = mbr.GenerateCodeTypeEmail
|
||||||
|
case "phone_verification":
|
||||||
|
ct = mbr.GenerateCodeTypePhone
|
||||||
|
default:
|
||||||
|
return &types.RespOK{}, errs.InputInvalidRangeError("failed to get correct verification type")
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := l.svcCtx.AccountUC.GetUserAccountInfo(l.ctx, member.GetUIDByAccountRequest{Account: token.LoginID(l.ctx)})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 先驗證,不刪除
|
||||||
|
if err = l.svcCtx.AccountUC.CheckRefreshCode(l.ctx, member.VerifyRefreshCodeRequest{
|
||||||
|
VerifyCode: req.VerifyCode,
|
||||||
|
LoginID: info.Data.LoginID,
|
||||||
|
CodeType: ct,
|
||||||
|
}); err != nil {
|
||||||
|
e := errs.AuthForbiddenError("failed to get verify code").Wrap(err)
|
||||||
|
|
||||||
|
return nil, e
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.RespOK{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"backend/internal/svc"
|
"backend/internal/svc"
|
||||||
"backend/internal/types"
|
"backend/internal/types"
|
||||||
|
errs "backend/pkg/library/errors"
|
||||||
|
mbr "backend/pkg/member/domain/member"
|
||||||
|
member "backend/pkg/member/domain/usecase"
|
||||||
|
tokeneEntity "backend/pkg/permission/domain/entity"
|
||||||
|
"backend/pkg/permission/domain/token"
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
@ -15,7 +19,7 @@ type UpdatePasswordLogic struct {
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改當前登入使用者的密碼
|
// NewUpdatePasswordLogic 修改當前登入使用者的密碼
|
||||||
func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
|
func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
|
||||||
return &UpdatePasswordLogic{
|
return &UpdatePasswordLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
|
|
@ -24,8 +28,41 @@ func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordReq) (resp *types.RespOK, err error) {
|
func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordReq) (*types.RespOK, error) {
|
||||||
// todo: add your logic here and delete this line
|
if req.NewPassword != req.NewPasswordConfirm {
|
||||||
|
return nil, errs.InputInvalidFormatError("failed to check token")
|
||||||
return
|
}
|
||||||
|
loginID := token.LoginID(l.ctx)
|
||||||
|
// 驗證是否本地平台
|
||||||
|
info, err := l.svcCtx.AccountUC.GetUserAccountInfo(l.ctx, member.GetUIDByAccountRequest{
|
||||||
|
Account: loginID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.Data.Platform != mbr.Digimon {
|
||||||
|
return nil, errs.InputInvalidFormatError("failed th change password via third party login")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 驗證舊密碼是否正確
|
||||||
|
if _, err := l.svcCtx.AccountUC.VerifyPlatformAuthResult(l.ctx, member.VerifyAuthResultRequest{
|
||||||
|
Account: loginID,
|
||||||
|
Token: req.CurrentPassword,
|
||||||
|
}); err != nil {
|
||||||
|
return nil, errs.AuthForbiddenError("failed to verify correct password")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新
|
||||||
|
err = l.svcCtx.AccountUC.UpdateUserToken(l.ctx, member.UpdateTokenRequest{
|
||||||
|
Account: loginID,
|
||||||
|
Token: req.NewPassword,
|
||||||
|
Platform: mbr.Digimon.ToInt64(),
|
||||||
|
})
|
||||||
|
|
||||||
|
_ = l.svcCtx.TokenUC.CancelToken(l.ctx, tokeneEntity.CancelTokenReq{
|
||||||
|
Token: req.Authorization.Authorization,
|
||||||
|
})
|
||||||
|
|
||||||
|
return &types.RespOK{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"backend/pkg/notification/config"
|
"backend/pkg/notification/config"
|
||||||
"backend/pkg/notification/domain/repository"
|
"backend/pkg/notification/domain/repository"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,14 +32,14 @@ func (repo *SMTPMailRepository) SendMail(ctx context.Context, req repository.Mai
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := req.From
|
|
||||||
if req.SenderName != "" {
|
|
||||||
sender = fmt.Sprintf("%s <%s>", req.SenderName, req.From)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 構建郵件
|
// 構建郵件
|
||||||
m := gomail.NewMessage()
|
m := gomail.NewMessage()
|
||||||
m.SetHeader("From", sender)
|
|
||||||
|
if req.SenderName != "" {
|
||||||
|
m.SetAddressHeader("From", req.From, req.SenderName)
|
||||||
|
} else {
|
||||||
|
m.SetHeader("From", req.From)
|
||||||
|
}
|
||||||
m.SetHeader("To", req.To...)
|
m.SetHeader("To", req.To...)
|
||||||
m.SetHeader("Subject", req.Subject)
|
m.SetHeader("Subject", req.Subject)
|
||||||
m.SetBody("text/html", req.Body)
|
m.SetBody("text/html", req.Body)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue