thread-master/old/backend/internal/logic/auth/resend_verification_email_l...

44 lines
1.2 KiB
Go

package auth
import (
"context"
"haixun-backend/internal/library/authctx"
app "haixun-backend/internal/library/errors"
"haixun-backend/internal/library/errors/code"
"haixun-backend/internal/svc"
"haixun-backend/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ResendVerificationEmailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewResendVerificationEmailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResendVerificationEmailLogic {
return &ResendVerificationEmailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ResendVerificationEmailLogic) ResendVerificationEmail() (*types.AuthResendVerificationData, error) {
actor, ok := authctx.ActorFromContext(l.ctx)
if !ok {
return nil, app.For(code.Auth).AuthUnauthorized("missing actor")
}
if l.svcCtx.Mailer == nil {
return nil, app.For(code.Auth).SysNotImplemented("smtp mailer is not configured")
}
err := l.svcCtx.Member.ResendEmailVerification(l.ctx, actor.TenantID, actor.UID, func(email, verifyCode string) error {
return sendEmailVerification(l.ctx, l.svcCtx, email, verifyCode)
})
if err != nil {
return nil, err
}
return &types.AuthResendVerificationData{Sent: true}, nil
}