From ba1a1319e340778ca37cdb94dabeb712ca696a68 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 25 Oct 2023 08:42:31 +0000 Subject: [PATCH] sigh --- cmd/help/email.go | 23 ++++++++++++++++++++++- cmd/help/main.go | 2 +- cmd/review/email.go | 21 +++++++++++++++++++++ email/email.go | 21 --------------------- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/cmd/help/email.go b/cmd/help/email.go index b4a4e76..7e79738 100644 --- a/cmd/help/email.go +++ b/cmd/help/email.go @@ -1,7 +1,9 @@ package main import ( + "errors" "fmt" + "os" "git.tilde.town/tildetown/town/email" ) @@ -23,8 +25,27 @@ Follow the instructions there to add your new key and restore access to your acc best, ~vilmibm` +func loadPassword() (string, error) { + f, err := os.Open("/town/docs/smtp_help.pw") + if err != nil { + return "", fmt.Errorf("could not open smtp password file: %w", err) + } + + pw := make([]byte, 100) + + n, err := f.Read(pw) + if err != nil { + return "", fmt.Errorf("could not read smtp password file: %w", err) + } + if n == 0 { + return "", errors.New("smtp password file was empty") + } + + return string(pw[0:n]), nil +} + func sendAuthCodeEmail(ac AuthCode) error { - pw, err := email.LoadPassword() + pw, err := loadPassword() if err != nil { return err } diff --git a/cmd/help/main.go b/cmd/help/main.go index 7836912..0bad197 100644 --- a/cmd/help/main.go +++ b/cmd/help/main.go @@ -326,7 +326,7 @@ type AuthCode struct { func (c *AuthCode) Insert(db *sql.DB) error { stmt, err := db.Prepare(` INSERT INTO auth_codes (code, email) - VALUES ?, ?`) + VALUES (?, ?)`) if err != nil { return err } diff --git a/cmd/review/email.go b/cmd/review/email.go index f5a3da0..27d865c 100644 --- a/cmd/review/email.go +++ b/cmd/review/email.go @@ -1,7 +1,9 @@ package main import ( + "errors" "fmt" + "os" "git.tilde.town/tildetown/town/email" "git.tilde.town/tildetown/town/invites" @@ -26,6 +28,25 @@ If you end up stuck, e-mail root@tilde.town with any questions. See you on the server, ~vilmibm` +func loadPassword() (string, error) { + f, err := os.Open("/town/docs/smtp.pw") + if err != nil { + return "", fmt.Errorf("could not open smtp password file: %w", err) + } + + pw := make([]byte, 100) + + n, err := f.Read(pw) + if err != nil { + return "", fmt.Errorf("could not read smtp password file: %w", err) + } + if n == 0 { + return "", errors.New("smtp password file was empty") + } + + return string(pw[0:n]), nil +} + func sendInviteEmail(invite invites.Invite) error { pw, err := email.LoadPassword() if err != nil { diff --git a/email/email.go b/email/email.go index 0acc8df..8588dc2 100644 --- a/email/email.go +++ b/email/email.go @@ -3,10 +3,8 @@ package email import ( "bytes" "crypto/tls" - "errors" "fmt" "net/smtp" - "os" "os/exec" ) @@ -16,25 +14,6 @@ const ( SMTPPort = 465 ) -func LoadPassword() (string, error) { - f, err := os.Open("/town/docs/smtp.pw") - if err != nil { - return "", fmt.Errorf("could not open smtp password file: %w", err) - } - - pw := make([]byte, 100) - - n, err := f.Read(pw) - if err != nil { - return "", fmt.Errorf("could not read smtp password file: %w", err) - } - if n == 0 { - return "", errors.New("smtp password file was empty") - } - - return string(pw[0:n]), nil -} - func SendLocalEmail(username, subject, body string) error { cmd := exec.Command("/usr/sbin/sendmail", username) cmd.Stdin = bytes.NewBufferString(fmt.Sprintf("Subject: %s\n\n%s", subject, body))