forked from tildetown/town
sigh
parent
cbc868ae35
commit
ba1a1319e3
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue