diff --git a/controller/account.go b/controller/account.go index 7190db22..723a6786 100644 --- a/controller/account.go +++ b/controller/account.go @@ -10,8 +10,24 @@ import ( "github.com/sirupsen/logrus" ) -func createAccountHandler(params identity.CreateAccountParams) middleware.Responder { +type createAccountHandler struct { + cfg *Config +} + +func newCreateAccountHandler(cfg *Config) *createAccountHandler { + return &createAccountHandler{cfg: cfg} +} + +func (self *createAccountHandler) Handle(params identity.CreateAccountParams) middleware.Responder { logrus.Infof("received account request for email '%v'", params.Body.Email) + if self.cfg.Registration.ImmediateCreate { + return self.handleDirectCreate(params) + } else { + return self.handleVerifiedCreate(params) + } +} + +func (self *createAccountHandler) handleDirectCreate(params identity.CreateAccountParams) middleware.Responder { if params.Body == nil || params.Body.Email == "" || params.Body.Password == "" { logrus.Errorf("missing email or password") return identity.NewCreateAccountBadRequest().WithPayload("missing email or password") @@ -46,6 +62,10 @@ func createAccountHandler(params identity.CreateAccountParams) middleware.Respon return identity.NewCreateAccountCreated().WithPayload(&rest_model_zrok.AccountResponse{Token: token}) } +func (self *createAccountHandler) handleVerifiedCreate(params identity.CreateAccountParams) middleware.Responder { + return identity.NewCreateAccountCreated() +} + func hashPassword(raw string) string { hash := sha512.New() hash.Write([]byte(raw)) diff --git a/controller/config.go b/controller/config.go index 5d3d51d6..1317307a 100644 --- a/controller/config.go +++ b/controller/config.go @@ -33,8 +33,9 @@ type EmailConfig struct { } type RegistrationConfig struct { - EmailFrom string - VerifyUrlTemplate string + ImmediateCreate bool + EmailFrom string + RegistrationUrlTemplate string } type ZitiConfig struct { diff --git a/controller/controller.go b/controller/controller.go index 96edb6cb..b849a74b 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -21,7 +21,7 @@ func Run(cfg *Config) error { api := operations.NewZrokAPI(swaggerSpec) api.KeyAuth = ZrokAuthenticate - api.IdentityCreateAccountHandler = identity.CreateAccountHandlerFunc(createAccountHandler) + api.IdentityCreateAccountHandler = newCreateAccountHandler(cfg) api.IdentityEnableHandler = newEnableHandler(cfg) api.IdentityDisableHandler = newDisableHandler(cfg) api.IdentityLoginHandler = identity.LoginHandlerFunc(loginHandler)