Add configuration option to disable signup

close #51

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-19 16:43:49 +01:00
parent a72c0269bb
commit ffa4c93bfd
4 changed files with 32 additions and 10 deletions

View File

@@ -32,10 +32,11 @@ import (
type (
Service struct {
pg *pg.Client
hp *passwdhash.Profile
hostname string
tokenSecret string
pg *pg.Client
hp *passwdhash.Profile
hostname string
tokenSecret string
disableSignup bool
}
ErrInvalidCredentials struct {
@@ -70,6 +71,8 @@ type (
message string
}
ErrSignupDisabled struct{}
EmailConfirmationData struct {
UserID gid.GID `json:"uid"`
Email string `json:"email"`
@@ -138,18 +141,24 @@ func (e ErrInvalidTokenType) Error() string {
return e.message
}
func (e ErrSignupDisabled) Error() string {
return "signup is disabled, contact the owner of the Probo instance"
}
func NewService(
ctx context.Context,
pgClient *pg.Client,
hp *passwdhash.Profile,
tokenSecret string,
hostname string,
disableSignup bool,
) (*Service, error) {
return &Service{
pg: pgClient,
hp: hp,
hostname: hostname,
tokenSecret: tokenSecret,
pg: pgClient,
hp: hp,
hostname: hostname,
tokenSecret: tokenSecret,
disableSignup: disableSignup,
}, nil
}
@@ -157,6 +166,10 @@ func (s Service) SignUp(
ctx context.Context,
email, password, fullName string,
) (*coredata.User, *coredata.Session, error) {
if s.disableSignup {
return nil, nil, &ErrSignupDisabled{}
}
if !strings.Contains(email, "@") {
return nil, nil, &ErrInvalidEmail{email}
}