sigh
parent
cbc868ae35
commit
ba1a1319e3
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.tilde.town/tildetown/town/email"
|
"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,
|
best,
|
||||||
~vilmibm`
|
~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 {
|
func sendAuthCodeEmail(ac AuthCode) error {
|
||||||
pw, err := email.LoadPassword()
|
pw, err := loadPassword()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,7 +326,7 @@ type AuthCode struct {
|
||||||
func (c *AuthCode) Insert(db *sql.DB) error {
|
func (c *AuthCode) Insert(db *sql.DB) error {
|
||||||
stmt, err := db.Prepare(`
|
stmt, err := db.Prepare(`
|
||||||
INSERT INTO auth_codes (code, email)
|
INSERT INTO auth_codes (code, email)
|
||||||
VALUES ?, ?`)
|
VALUES (?, ?)`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.tilde.town/tildetown/town/email"
|
"git.tilde.town/tildetown/town/email"
|
||||||
"git.tilde.town/tildetown/town/invites"
|
"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,
|
See you on the server,
|
||||||
~vilmibm`
|
~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 {
|
func sendInviteEmail(invite invites.Invite) error {
|
||||||
pw, err := email.LoadPassword()
|
pw, err := email.LoadPassword()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,10 +3,8 @@ package email
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,25 +14,6 @@ const (
|
||||||
SMTPPort = 465
|
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 {
|
func SendLocalEmail(username, subject, body string) error {
|
||||||
cmd := exec.Command("/usr/sbin/sendmail", username)
|
cmd := exec.Command("/usr/sbin/sendmail", username)
|
||||||
cmd.Stdin = bytes.NewBufferString(fmt.Sprintf("Subject: %s\n\n%s", subject, body))
|
cmd.Stdin = bytes.NewBufferString(fmt.Sprintf("Subject: %s\n\n%s", subject, body))
|
||||||
|
|
Loading…
Reference in New Issue