Compare commits
2 Commits
2a07a0e200
...
be5020ad28
Author | SHA1 | Date |
---|---|---|
vilmibm | be5020ad28 | |
vilmibm | 9bea4257c1 |
|
@ -9,3 +9,5 @@ cmd/welcome/welcome
|
||||||
cmd/createkeyfile/createkeyfile
|
cmd/createkeyfile/createkeyfile
|
||||||
cmd/registeruser/registeruser
|
cmd/registeruser/registeruser
|
||||||
cmd/stats/stats
|
cmd/stats/stats
|
||||||
|
cmd/appendkeyfile/appendkeyfile
|
||||||
|
cmd/help/help
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// TODO accept an email as an argument, write out a username associated with it or throw an error
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("TODO")
|
||||||
|
}
|
|
@ -22,6 +22,15 @@ import (
|
||||||
|
|
||||||
// TODO put colorscheme, prompting stuff into own packages for use in the other commands. would be good to get off of survey.
|
// TODO put colorscheme, prompting stuff into own packages for use in the other commands. would be good to get off of survey.
|
||||||
|
|
||||||
|
func connectDB() (*sql.DB, error) {
|
||||||
|
db, err := sql.Open("sqlite3", "/town/var/codes/codes.db?mode=rw")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
|
|
||||||
type colorScheme struct {
|
type colorScheme struct {
|
||||||
Header func(string) string
|
Header func(string) string
|
||||||
Subtitle func(string) string
|
Subtitle func(string) string
|
||||||
|
@ -108,7 +117,7 @@ func (p *Prompter) Select(prompt string, opts []string) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _main(cs colorScheme) error {
|
func _main(cs colorScheme) error {
|
||||||
db, err := towndb.ConnectDB()
|
db, err := connectDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not connect to database. please let root@tilde.town know about this.")
|
return fmt.Errorf("could not connect to database. please let root@tilde.town know about this.")
|
||||||
}
|
}
|
||||||
|
@ -149,6 +158,12 @@ func _main(cs colorScheme) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userToEmail(email string) (string, error) {
|
||||||
|
// TODO shell out to /town/src/town/cmd/usertoemail
|
||||||
|
// TODO add to sudoers
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
func collectEmail(db *sql.DB, cs colorScheme, p *Prompter) error {
|
func collectEmail(db *sql.DB, cs colorScheme, p *Prompter) error {
|
||||||
fmt.Println(cs.Header("We can send a authorization code to an email associated with your town account."))
|
fmt.Println(cs.Header("We can send a authorization code to an email associated with your town account."))
|
||||||
email, err := p.String("email to send reset code to?")
|
email, err := p.String("email to send reset code to?")
|
||||||
|
@ -274,11 +289,6 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error {
|
||||||
return errors.New("adding to keys file failed")
|
return errors.New("adding to keys file failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add help user
|
|
||||||
// TODO update sshd_config
|
|
||||||
// TODO update sudoers
|
|
||||||
// TODO compile appendkeyfile and add to /town/bin/
|
|
||||||
|
|
||||||
err = code.MarkUsed(db)
|
err = code.MarkUsed(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO log err
|
// TODO log err
|
||||||
|
@ -288,6 +298,13 @@ func redeemCode(db *sql.DB, cs colorScheme, p *Prompter) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO db plan:
|
||||||
|
|
||||||
|
// add new db, codes (modeled after invites)
|
||||||
|
// add new helper, emailtouser, that can access town.db and report on what user matches a given email
|
||||||
|
// drop table from town.db
|
||||||
|
// update sshapps.md
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cs := newColorScheme()
|
cs := newColorScheme()
|
||||||
err := _main(cs)
|
err := _main(cs)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS auth_codes (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
|
||||||
|
code TEXT,
|
||||||
|
email TEXT,
|
||||||
|
used INTEGER DEFAULT 0
|
||||||
|
);
|
|
@ -32,11 +32,3 @@ CREATE TABLE IF NOT EXISTS notes (
|
||||||
|
|
||||||
FOREIGN KEY (author) REFERENCES users(author)
|
FOREIGN KEY (author) REFERENCES users(author)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS auth_codes (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
|
|
||||||
code TEXT,
|
|
||||||
email TEXT,
|
|
||||||
used INTEGER DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
Loading…
Reference in New Issue