mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
parent
97481e7df7
commit
600f0396d2
@ -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))
|
||||
|
@ -33,8 +33,9 @@ type EmailConfig struct {
|
||||
}
|
||||
|
||||
type RegistrationConfig struct {
|
||||
EmailFrom string
|
||||
VerifyUrlTemplate string
|
||||
ImmediateCreate bool
|
||||
EmailFrom string
|
||||
RegistrationUrlTemplate string
|
||||
}
|
||||
|
||||
type ZitiConfig struct {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user