This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/login/main.go

56 lines
1.1 KiB
Go

package main
import (
gc "github.com/rthornton128/goncurses"
)
const URLLogin = "http://172.23.0.1:8081/login"
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)
gc.InitPair(5, gc.C_BLACK, gc.C_WHITE)
// 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)
}
}