Verification emails
This commit is contained in:
57
api/v1/email.go
Normal file
57
api/v1/email.go
Normal file
@ -0,0 +1,57 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/email"
|
||||
proto_email "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/email"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
type EmailServer struct {
|
||||
proto_email.UnimplementedEmailValidationServer
|
||||
emailConfig email.EmailConf
|
||||
controller ctrl.Manager
|
||||
|
||||
}
|
||||
|
||||
func InitEmailServer(controller ctrl.Manager, emailConfig *email.EmailConf) *EmailServer {
|
||||
return &EmailServer{
|
||||
controller: controller,
|
||||
emailConfig: *emailConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *EmailServer) SendRequest(ctx context.Context, in *proto_email.RequestValidation) (*emptypb.Empty, error) {
|
||||
emailSvc := controllers.EmailSvc {
|
||||
Data: controllers.EmailData{
|
||||
UserID: in.GetUserId(),
|
||||
},
|
||||
EmailConfig: c.emailConfig,
|
||||
Controller: c.controller,
|
||||
}
|
||||
err := emailSvc.SendVerification(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (c *EmailServer) ValidateEmail(ctx context.Context, in *proto_email.ConfirmValidation) (*emptypb.Empty, error) {
|
||||
emailSvc := controllers.EmailSvc {
|
||||
Data: controllers.EmailData{
|
||||
UserID: in.GetUserId(),
|
||||
Code: fmt.Sprintf("%d", in.GetCode()),
|
||||
},
|
||||
EmailConfig: c.emailConfig,
|
||||
Controller: c.controller,
|
||||
}
|
||||
err := emailSvc.ConfirmVerification(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
Reference in New Issue
Block a user