2018-02-10 12:54:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gc "github.com/rthornton128/goncurses"
|
|
|
|
)
|
|
|
|
|
2018-02-10 13:37:23 +00:00
|
|
|
const URLLogin = "http://172.23.0.1:8081/login"
|
2018-02-10 12:54:18 +00:00
|
|
|
|
|
|
|
func goLogin(stdscr *gc.Window, in chan gc.Key) (string, bool) {
|
|
|
|
username, password := login(stdscr, in)
|
|
|
|
|
|
|
|
validator := make(chan error)
|
|
|
|
go func(username, password string, progress chan error) {
|
|
|
|
_, err := checkLogin(username, password)
|
|
|
|
progress <- err
|
|
|
|
}(username, password, validator)
|
|
|
|
|
|
|
|
if connection(stdscr, in, validator) {
|
|
|
|
return username, true
|
|
|
|
} else {
|
|
|
|
return goLogin(stdscr, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
stdscr, _ := gc.Init()
|
|
|
|
defer gc.End()
|
|
|
|
|
|
|
|
// Set main properties
|
|
|
|
gc.Cursor(0)
|
|
|
|
gc.StartColor()
|
|
|
|
gc.Raw(true)
|
|
|
|
gc.Echo(false)
|
|
|
|
stdscr.Keypad(true)
|
|
|
|
|
|
|
|
// Define colors
|
|
|
|
gc.InitPair(1, gc.C_WHITE, gc.C_BLUE)
|
|
|
|
gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
|
|
|
|
gc.InitPair(3, gc.C_CYAN, gc.C_BLACK)
|
|
|
|
gc.InitPair(4, gc.C_RED, gc.C_BLACK)
|
2018-02-10 13:37:23 +00:00
|
|
|
gc.InitPair(5, gc.C_BLACK, gc.C_WHITE)
|
2018-02-10 12:54:18 +00:00
|
|
|
|
|
|
|
// Register pressed key through channel
|
|
|
|
in := make(chan gc.Key)
|
|
|
|
go func(w *gc.Window, ch chan<- gc.Key) {
|
|
|
|
for {
|
|
|
|
ch <- w.GetChar()
|
|
|
|
}
|
|
|
|
}(stdscr, in)
|
|
|
|
|
|
|
|
// Run!
|
|
|
|
if username, ok := goLogin(stdscr, in); ok {
|
|
|
|
okreboot(stdscr, username)
|
|
|
|
}
|
|
|
|
}
|