mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
parent
712bdf734b
commit
aa19870d41
@ -63,6 +63,19 @@ func (self *createAccountHandler) handleDirectCreate(params identity.CreateAccou
|
||||
}
|
||||
|
||||
func (self *createAccountHandler) handleVerifiedCreate(params identity.CreateAccountParams) middleware.Responder {
|
||||
if params.Body == nil || params.Body.Email == "" {
|
||||
logrus.Errorf("missing email")
|
||||
return identity.NewCreateAccountBadRequest().WithPayload("missing email")
|
||||
}
|
||||
token, err := generateApiToken()
|
||||
if err != nil {
|
||||
logrus.Errorf("error generating api token: %v", err)
|
||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
if err := sendVerificationEmail(params.Body.Email, token, self.cfg); err != nil {
|
||||
logrus.Error(err)
|
||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
return identity.NewCreateAccountCreated()
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ type ProxyConfig struct {
|
||||
|
||||
type EmailConfig struct {
|
||||
Host string
|
||||
Port uint16
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
@ -29,9 +29,12 @@ func sendVerificationEmail(emailAddress, token string, cfg *Config) error {
|
||||
return errors.Wrap(err, "error executing email verification template")
|
||||
}
|
||||
|
||||
subject := "Subject: Welcome to zrok!\n"
|
||||
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
|
||||
msg := []byte(subject + mime + buf.String())
|
||||
auth := smtp.PlainAuth("", cfg.Email.Username, cfg.Email.Password, cfg.Email.Host)
|
||||
to := []string{emailAddress}
|
||||
err = smtp.SendMail(fmt.Sprintf("%v:%d", cfg.Email.Host, cfg.Email.Port), auth, cfg.Registration.EmailFrom, to, buf.Bytes())
|
||||
err = smtp.SendMail(fmt.Sprintf("%v:%d", cfg.Email.Host, cfg.Email.Port), auth, cfg.Registration.EmailFrom, to, msg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error sending email verification")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user