From 90834601d7720fd15d838b8410698984e8aaa2dc Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 26 Feb 2024 08:15:10 -0500 Subject: [PATCH] refactor: modify CreateAccount to optionally send an email verification --- account/account.go | 9 ++++++++- api/s5/s5.go | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/account/account.go b/account/account.go index f4ec250..15c9d49 100644 --- a/account/account.go +++ b/account/account.go @@ -82,7 +82,7 @@ func (s *AccountServiceDefault) HashPassword(password string) (string, error) { return string(bytes), nil } -func (s *AccountServiceDefault) CreateAccount(email string, password string) (*models.User, error) { +func (s *AccountServiceDefault) CreateAccount(email string, password string, verifyEmail bool) (*models.User, error) { passwordHash, err := s.HashPassword(password) if err != nil { return nil, err @@ -98,6 +98,13 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string) (*m return nil, NewAccountError(ErrKeyAccountCreationFailed, result.Error) } + if verifyEmail { + err = s.SendEmailVerification(&user) + if err != nil { + return nil, err + } + } + return &user, nil } diff --git a/api/s5/s5.go b/api/s5/s5.go index e4e54d2..0ecf1dd 100644 --- a/api/s5/s5.go +++ b/api/s5/s5.go @@ -10,11 +10,6 @@ import ( "encoding/hex" "errors" "fmt" - "git.lumeweb.com/LumeWeb/portal/api/router" - "git.lumeweb.com/LumeWeb/portal/bao" - "git.lumeweb.com/LumeWeb/portal/renter" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/s3" "io" "math" "mime/multipart" @@ -24,6 +19,12 @@ import ( "strings" "time" + "git.lumeweb.com/LumeWeb/portal/api/router" + "git.lumeweb.com/LumeWeb/portal/bao" + "git.lumeweb.com/LumeWeb/portal/renter" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3" + "git.lumeweb.com/LumeWeb/portal/cron" "git.lumeweb.com/LumeWeb/portal/config" @@ -57,7 +58,6 @@ import ( protoRegistry "git.lumeweb.com/LumeWeb/portal/protocols/registry" "git.lumeweb.com/LumeWeb/portal/protocols/s5" "github.com/ddo/rq" - "github.com/dnslink-std/go" "github.com/rs/cors" "go.sia.tech/jape" "go.uber.org/fx" @@ -565,7 +565,7 @@ func (s *S5API) accountRegister(jc jape.Context) { return } - newAccount, err := s.accounts.CreateAccount(request.Email, string(passwd)) + newAccount, err := s.accounts.CreateAccount(request.Email, string(passwd), false) if err != nil { s.sendErrorResponse(jc, NewS5Error(ErrKeyStorageOperationFailed, err)) return