call registeruser from welcome

pull/1/head
vilmibm 2023-03-06 19:33:36 +00:00
parent 55eb4b7010
commit 92807f9b6b
1 changed files with 22 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
@ -9,13 +10,17 @@ import (
"git.tilde.town/tildetown/town/invites"
"git.tilde.town/tildetown/town/stats"
"git.tilde.town/tildetown/town/towndb"
"github.com/charmbracelet/lipgloss"
_ "embed"
)
// TODO add logging like the signup tool has
// TODO consider merging adduser, usermod, and createkeyfile into single createuser helper to limit sudoers list
// TODO move magic key machine to static page
// TODO link to code of conduct as part of the form and ask if they agree
// TODO add alerts for new users (mailing list post, irc post, etc(?))
//go:embed welcome.txt
var welcomeArt string
@ -130,14 +135,11 @@ if you end up very stuck, you can email root@tilde.town .`, data.Username))
fmt.Println(s)
// TODO mark invite as used
// TODO invoke helper to add user to town.db
// TODO burn invite
return nil
}
// TODO add logging like the signup tool has
func createUser(data newUserData) (err error) {
cmd := exec.Command("sudo", "/usr/sbin/adduser", "--quiet", "--disabled-password", data.Username)
if err = cmd.Run(); err != nil {
@ -160,7 +162,22 @@ func createUser(data newUserData) (err error) {
// TODO log this. no reason to bail out.
}
// TODO any alerts
cmd = exec.Command("sudo", "/town/bin/registeruser")
tu := towndb.TownUser{
Username: data.Username,
Emails: []string{
data.Email,
},
State: towndb.StateActive,
}
var out []byte
if out, err = json.Marshal(tu); err != nil {
return fmt.Errorf("could not serialize user data: %w", err)
}
cmd.Stdin = bytes.NewBuffer(out)
if err = cmd.Run(); err != nil {
return fmt.Errorf("register user failed: %w", err)
}
return nil
}