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/pkg/login-app/cmd/main.go

85 lines
1.6 KiB
Go
Raw Normal View History

2018-02-10 12:54:18 +00:00
package main
import (
"math/rand"
"os"
"time"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
2018-02-10 12:54:18 +00:00
)
const URLLogin = "https://auth.adlin.nemunai.re/login"
2018-02-10 12:54:18 +00:00
var (
loggedAs = ""
)
func modal(p tview.Primitive, width, height int) tview.Primitive {
return tview.NewFlex().
AddItem(nil, 0, 1, false).
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(nil, 0, 1, false).
AddItem(p, height, 1, false).
AddItem(nil, 0, 1, false), width, 1, false).
AddItem(nil, 0, 1, false)
}
func askLogin(app *tview.Application) {
CreateLoginDialog(app, func(username, password string) {
// Display check dialog
CreateCheckDialog(app)
go func() {
if ok, err := checkLogin(username, password); ok {
loggedAs = username
app.Stop()
} else {
CreateErrMsgDialog(app, err)
}
}()
})
/*lgd.beforeClose = func() {
// Display next dialoag
ckd := CreateCheckDialog(" SRS AdLin - Login ", lgd.Username, lgd.Password)
ckd.beforeClose = func(ev ui.Event) {
if ev.Err == nil {
logged = true
CreateRebootDialog(" SRS AdLin - Login", lgd.Username)
} else {
errd := CreateErrMsgDialog(" SRS AdLin - Login ", ev.Err)
errd.beforeClose = func() {
askLogin()
}
}
}
}*/
2018-02-10 12:54:18 +00:00
}
func main() {
// seed the rand package with time
rand.Seed(time.Now().UnixNano())
app := tview.NewApplication()
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlQ {
app.Stop()
}
return event
})
askLogin(app)
if err := app.Run(); err != nil {
panic(err)
}
2018-02-10 12:54:18 +00:00
if loggedAs == "" {
os.Exit(1)
2018-02-10 12:54:18 +00:00
}
runCinematic(loggedAs)
2018-02-10 12:54:18 +00:00
}