refactor: modify CreateAccount to optionally send an email verification
This commit is contained in:
parent
8965395fdf
commit
90834601d7
|
@ -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
|
||||
}
|
||||
|
||||
|
|
14
api/s5/s5.go
14
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
|
||||
|
|
Loading…
Reference in New Issue