call registeruser from welcome
parent
55eb4b7010
commit
92807f9b6b
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -9,13 +10,17 @@ import (
|
||||||
|
|
||||||
"git.tilde.town/tildetown/town/invites"
|
"git.tilde.town/tildetown/town/invites"
|
||||||
"git.tilde.town/tildetown/town/stats"
|
"git.tilde.town/tildetown/town/stats"
|
||||||
|
"git.tilde.town/tildetown/town/towndb"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
_ "embed"
|
_ "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 move magic key machine to static page
|
||||||
// TODO link to code of conduct as part of the form and ask if they agree
|
// 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
|
//go:embed welcome.txt
|
||||||
var welcomeArt string
|
var welcomeArt string
|
||||||
|
@ -130,14 +135,11 @@ if you end up very stuck, you can email root@tilde.town .`, data.Username))
|
||||||
|
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
|
|
||||||
// TODO mark invite as used
|
// TODO burn invite
|
||||||
// TODO invoke helper to add user to town.db
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add logging like the signup tool has
|
|
||||||
|
|
||||||
func createUser(data newUserData) (err error) {
|
func createUser(data newUserData) (err error) {
|
||||||
cmd := exec.Command("sudo", "/usr/sbin/adduser", "--quiet", "--disabled-password", data.Username)
|
cmd := exec.Command("sudo", "/usr/sbin/adduser", "--quiet", "--disabled-password", data.Username)
|
||||||
if err = cmd.Run(); err != nil {
|
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 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue