forked from tildetown/town
send auth code email
parent
a3b13d21b3
commit
6950ba7109
|
@ -172,13 +172,16 @@ func collectEmail(db *sql.DB, cs colorScheme, tty *tty.TTY) error {
|
|||
Email: email,
|
||||
}
|
||||
|
||||
err = ac.Insert(db)
|
||||
if err != nil {
|
||||
if err = ac.Insert(db); err != nil {
|
||||
// TODO log
|
||||
return err
|
||||
}
|
||||
|
||||
if err = sendAuthCodeEmail(*ac); err != nil {
|
||||
// TODO log
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO send email
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.tilde.town/tildetown/town/email"
|
||||
"git.tilde.town/tildetown/town/invites"
|
||||
|
@ -28,27 +26,8 @@ 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 "", err
|
||||
}
|
||||
|
||||
pw := make([]byte, 100)
|
||||
|
||||
n, err := f.Read(pw)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if n == 0 {
|
||||
return "", errors.New("read nothing")
|
||||
}
|
||||
|
||||
return string(pw[0:n]), nil
|
||||
}
|
||||
|
||||
func sendInviteEmail(invite invites.Invite) error {
|
||||
pw, err := loadPassword()
|
||||
pw, err := email.LoadPassword()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read password: %w", err)
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package email
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
|
@ -14,6 +16,25 @@ 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))
|
||||
|
|
Loading…
Reference in New Issue