68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.tilde.town/tildetown/town/email"
|
|
"git.tilde.town/tildetown/town/invites"
|
|
)
|
|
|
|
const emailText = `hello!
|
|
|
|
You applied to https://tilde.town at some point and your application has been approved ^_^
|
|
|
|
Your invite code is: %s
|
|
|
|
To redeem your code, please open a terminal and run:
|
|
|
|
ssh welcome@tilde.town
|
|
|
|
You'll fill in details like your desired username and SSH public key.
|
|
|
|
If you're brand new to SSH or have never heard of it that is okay!
|
|
|
|
This page has information on what SSH is and how to use it, including how to create an ssh key pair which you'll need to access your town account: https://tilde.town/wiki/getting-started/ssh.html
|
|
|
|
If you run into confusion or problems creating a key pair on your computer, this page can generate one for you: https://tilde.town/keymachine . However you'll still need to save the generated key files to your computer in order to use them.
|
|
|
|
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()
|
|
if err != nil {
|
|
return fmt.Errorf("could not read password: %w", err)
|
|
}
|
|
|
|
body := fmt.Sprintf(emailText, invite.Code)
|
|
|
|
mailer := email.NewExternalMailer(pw)
|
|
return mailer.Send(
|
|
invite.Email,
|
|
"your tilde.town application was accepted",
|
|
body)
|
|
}
|