Compare commits

...

3 Commits

Author SHA1 Message Date
Harvey Tindall 548dceda28
don't give smtp plainauth if no username & password
for #141, just a guess
2021-08-26 21:03:02 +01:00
Harvey Tindall e67b2e91fb
invite: auto-append /invite if missing to url_base 2021-08-26 18:53:22 +01:00
Harvey Tindall 412fe31da6
invite: fix email confirmation jwt
same issue as with auth.go, expiry was a string causing the library to
see it as expired.
2021-08-26 18:39:50 +01:00
5 changed files with 17 additions and 9 deletions

2
api.go
View File

@ -418,7 +418,7 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
"username": req.Username, "username": req.Username,
"password": req.Password, "password": req.Password,
"telegramPIN": req.TelegramPIN, "telegramPIN": req.TelegramPIN,
"exp": strconv.FormatInt(time.Now().Add(time.Hour*12).Unix(), 10), "exp": time.Now().Add(time.Hour * 12).Unix(),
"type": "confirmation", "type": "confirmation",
} }
tk := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) tk := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

View File

@ -246,7 +246,7 @@
"requires_restart": true, "requires_restart": true,
"type": "text", "type": "text",
"value": "", "value": "",
"description": "URL base for when running jfa-go with a reverse proxy in a subfolder." "description": "URL base for when running jfa-go with a reverse proxy in a subfolder. include preceding /, e.g \"/accounts\"."
} }
} }
}, },

View File

@ -181,8 +181,7 @@ func (emailer *Emailer) NewMailgun(url, key string) {
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string) (err error) { func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string) (err error) {
// x509.SystemCertPool is unavailable on windows // x509.SystemCertPool is unavailable on windows
if PLATFORM == "windows" { if PLATFORM == "windows" {
emailer.sender = &SMTP{ sender := &SMTP{
auth: smtp.PlainAuth("", username, password, server),
server: server, server: server,
port: port, port: port,
sslTLS: sslTLS, sslTLS: sslTLS,
@ -191,6 +190,10 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
ServerName: server, ServerName: server,
}, },
} }
if username != "" || password != "" {
sender.auth = smtp.PlainAuth("", username, password, server)
}
emailer.sender = sender
return return
} }
rootCAs, err := x509.SystemCertPool() rootCAs, err := x509.SystemCertPool()
@ -204,8 +207,7 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
err = errors.New("Failed to append cert to pool") err = errors.New("Failed to append cert to pool")
} }
} }
emailer.sender = &SMTP{ sender := &SMTP{
auth: smtp.PlainAuth("", username, password, server),
server: server, server: server,
port: port, port: port,
sslTLS: sslTLS, sslTLS: sslTLS,
@ -215,6 +217,10 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
RootCAs: rootCAs, RootCAs: rootCAs,
}, },
} }
if username != "" || password != "" {
sender.auth = smtp.PlainAuth("", username, password, server)
}
emailer.sender = sender
return return
} }
@ -306,6 +312,9 @@ func (emailer *Emailer) confirmationValues(code, username, key string, app *appC
} else { } else {
message := app.config.Section("messages").Key("message").String() message := app.config.Section("messages").Key("message").String()
inviteLink := app.config.Section("invite_emails").Key("url_base").String() inviteLink := app.config.Section("invite_emails").Key("url_base").String()
if !strings.HasSuffix(inviteLink, "/invite") {
inviteLink += "/invite"
}
inviteLink = fmt.Sprintf("%s/%s?key=%s", inviteLink, code, key) inviteLink = fmt.Sprintf("%s/%s?key=%s", inviteLink, code, key)
template["helloUser"] = emailer.lang.Strings.template("helloUser", tmpl{"username": username}) template["helloUser"] = emailer.lang.Strings.template("helloUser", tmpl{"username": username})
template["confirmationURL"] = inviteLink template["confirmationURL"] = inviteLink

View File

@ -100,7 +100,7 @@ func migrateEmailStorage(app *appContext) error {
case map[string]interface{}: case map[string]interface{}:
return nil return nil
default: default:
return fmt.Errorf("Email address was type %T, not string: \"%+v\"\n", addr, addr) return fmt.Errorf("email address was type %T, not string: \"%+v\"\n", addr, addr)
} }
} }
config, err := ini.Load(app.configPath) config, err := ini.Load(app.configPath)

View File

@ -4,7 +4,6 @@ import (
"html/template" "html/template"
"io/fs" "io/fs"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
@ -249,7 +248,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
return return
} }
claims, ok := token.Claims.(jwt.MapClaims) claims, ok := token.Claims.(jwt.MapClaims)
expiryUnix, err := strconv.ParseInt(claims["exp"].(string), 10, 64) expiryUnix := int64(claims["exp"].(float64))
if err != nil { if err != nil {
fail() fail()
app.err.Printf("Failed to parse key expiry: %s", err) app.err.Printf("Failed to parse key expiry: %s", err)