mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 17:43:53 +01:00
parent
97481e7df7
commit
600f0396d2
@ -10,8 +10,24 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"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)
|
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 == "" {
|
if params.Body == nil || params.Body.Email == "" || params.Body.Password == "" {
|
||||||
logrus.Errorf("missing email or password")
|
logrus.Errorf("missing email or password")
|
||||||
return identity.NewCreateAccountBadRequest().WithPayload("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})
|
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 {
|
func hashPassword(raw string) string {
|
||||||
hash := sha512.New()
|
hash := sha512.New()
|
||||||
hash.Write([]byte(raw))
|
hash.Write([]byte(raw))
|
||||||
|
@ -33,8 +33,9 @@ type EmailConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RegistrationConfig struct {
|
type RegistrationConfig struct {
|
||||||
EmailFrom string
|
ImmediateCreate bool
|
||||||
VerifyUrlTemplate string
|
EmailFrom string
|
||||||
|
RegistrationUrlTemplate string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZitiConfig struct {
|
type ZitiConfig struct {
|
||||||
|
@ -21,7 +21,7 @@ func Run(cfg *Config) error {
|
|||||||
|
|
||||||
api := operations.NewZrokAPI(swaggerSpec)
|
api := operations.NewZrokAPI(swaggerSpec)
|
||||||
api.KeyAuth = ZrokAuthenticate
|
api.KeyAuth = ZrokAuthenticate
|
||||||
api.IdentityCreateAccountHandler = identity.CreateAccountHandlerFunc(createAccountHandler)
|
api.IdentityCreateAccountHandler = newCreateAccountHandler(cfg)
|
||||||
api.IdentityEnableHandler = newEnableHandler(cfg)
|
api.IdentityEnableHandler = newEnableHandler(cfg)
|
||||||
api.IdentityDisableHandler = newDisableHandler(cfg)
|
api.IdentityDisableHandler = newDisableHandler(cfg)
|
||||||
api.IdentityLoginHandler = identity.LoginHandlerFunc(loginHandler)
|
api.IdentityLoginHandler = identity.LoginHandlerFunc(loginHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user