From 33ea591651d8a8f2333ca9f831ab4d4c1fbc779a Mon Sep 17 00:00:00 2001 From: vilmibm Date: Sun, 26 Feb 2023 08:57:46 +0000 Subject: [PATCH] WIP on welcome tool --- cmd/welcome/README.md | 3 +- cmd/welcome/main.go | 83 ++++++++++++++++++++++++++++++++++++++++- cmd/welcome/welcome.txt | 19 ++++++++++ signup/signup.go | 2 + 4 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 cmd/welcome/welcome.txt diff --git a/cmd/welcome/README.md b/cmd/welcome/README.md index c4c3cfd..3e5423c 100644 --- a/cmd/welcome/README.md +++ b/cmd/welcome/README.md @@ -7,8 +7,7 @@ responsible for: 2. accepting and validating a new user's username choice (ie enforcing rules and checking for dupes) 3. accepting and validating a user's email for use in account recovery (defaulting to an email embedded in the invite token) 4. accepting and validating a display name -5. asking what shell they'd like -6. accepting and validating a user's public ssh key +5. accepting and validating a user's public ssh key upon receipt of these things a user account is created. if it fails, the user is told about the failure and told to email root@tilde.town for guidance; us diff --git a/cmd/welcome/main.go b/cmd/welcome/main.go index 2d7bffa..042d615 100644 --- a/cmd/welcome/main.go +++ b/cmd/welcome/main.go @@ -1,7 +1,86 @@ package main -import "fmt" +import ( + "fmt" + "os" + + "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" + + _ "embed" +) + +//go:embed welcome.txt +var welcomeArt string + +// TODO remove ConnectDB abstraction in favor of just connecting directly to sqliteh +// TODO move magic key machine to static page + +type newUserData struct { + Username string + DisplayName string + Email string + PubKey string +} + +func _main() error { + app := tview.NewApplication() + //data := &newUserData{} + + help := tview.NewTextView() + help.SetText("tab+enter or mouse to submit. ctrl+c to quit.") + help.SetTextColor(tcell.ColorGray) + + artView := tview.NewTextView() + artView.SetText(welcomeArt) + artView.SetDynamicColors(true) + artView.SetBackgroundColor(tcell.ColorBlack) + artView.SetTextColor(tcell.ColorPurple) + + // TODO colors wacky + tokenInput := tview.NewInputField() + tokenInput.SetLabel("invite code:") + tokenInput.SetFieldWidth(40) + + tokenForm := tview.NewForm() + tokenForm.SetButtonBackgroundColor(tcell.ColorPurple) + tokenForm.SetButtonTextColor(tcell.ColorBlack) + tokenForm.SetButtonActivatedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorPurple)) + + tokenForm.SetLabelColor(tcell.ColorPurple) + tokenForm.SetFieldBackgroundColor(tcell.ColorPurple) + tokenForm.AddFormItem(tokenInput) + tokenForm.AddButton("submit", func() { + app.Stop() + // TODO + }) + + tokenPage := tview.NewFlex() + tokenPage.SetDirection(tview.FlexRow) + tokenPage.AddItem(artView, 17, -1, false) + tokenPage.AddItem(tokenForm, 5, -1, true) + tokenPage.AddItem(help, 1, -1, false) + + pages := tview.NewPages() + pages.AddPage("start", tokenPage, true, true) + + app.SetRoot(pages, true) + + /* + TODO multi-page flow: + - page 1: accept invite token + - page 2: username, display name, email + - page 3: public key + - page 4: next steps + */ + + return app.EnableMouse(true).Run() +} func main() { - fmt.Println("welcome") + err := _main() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } } diff --git a/cmd/welcome/welcome.txt b/cmd/welcome/welcome.txt new file mode 100644 index 0000000..a073398 --- /dev/null +++ b/cmd/welcome/welcome.txt @@ -0,0 +1,19 @@ + _ ( ) . ' + | | . + _ | | __ __ _ _ _ _ _|_ __ __ : +| | |_|/ |/ / / \_/ |/ |/ | |/ | / \_ / /\ __ ___!__ _,__ ___,_ + \/ \/ |__/|__/\___/\__/ | | |_/|__/ |_/\__/ / / o\/ \ / /\ /__/ \ /__\__\ + / \\ \/_____ /_*\ | |[^][^| | | + _ / /\ | | |_|__| .: |__|__| + o | | | || | {^} | | +_|_ | | __| _ _|_ __ _ _ [] [] | | | |. . A ._ . . + | | |/ / | |/ | / \_| | |_/ |/ | _ _ |___|__|__D_| . H / \ {^} + |_/|_/|__/\_/|_/|__/o|_/\__/ \/ \/ | |_/ | |[@] | | . . . | |/ \ | + _|_|_____| . . |^| \ | + . . v v . | | \|. + . v v . / O \ /| + |_ u _| . . / _ \ / | + we're glad you're here || | || / |_| \/ | + | | |. + + diff --git a/signup/signup.go b/signup/signup.go index 72d3562..e7c6cc5 100644 --- a/signup/signup.go +++ b/signup/signup.go @@ -1,5 +1,7 @@ package signup +// TODO delete this file + import ( "database/sql"