felt/cmd/cmd.go

49 lines
898 B
Go

package cmd
import (
"fmt"
"hacklab.nilfm.cc/felt/register"
"hacklab.nilfm.cc/quartzgun/auth"
"strconv"
"time"
)
func ProcessCmd(args []string, userStore auth.UserStore, crypto register.SymmetricCrypto) bool {
if len(args) == 1 {
return false
}
switch args[1] {
case "invite":
now := time.Now().UnixMicro()
strNow := strconv.FormatInt(now, 10)
self, err := crypto.Encrypt(strNow)
if err == nil {
fmt.Print("This is the registration key: ")
fmt.Println(self)
} else {
fmt.Printf("%v\n", err)
}
case "adduser":
if len(args) < 4 {
return help()
}
userStore.AddUser(args[2], args[3])
case "rmuser":
if len(args) < 3 {
return help()
}
userStore.DeleteUser(args[2])
case "passwd":
if len(args) < 5 {
return help()
}
userStore.ChangePassword(args[2], args[3], args[4])
default:
help()
}
return true
}
func help() bool {
return true
}