Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net/http"
- "net/http/cookiejar"
- "fyne.io/fyne"
- "fyne.io/fyne/app"
- "fyne.io/fyne/layout"
- "fyne.io/fyne/widget"
- )
- type State struct {
- app fyne.App
- client *http.Client
- loginw fyne.Window
- mainapp fyne.App
- mainw fyne.Window
- }
- func main() {
- var state State
- cookieJar, _ := cookiejar.New(nil)
- state.client = &http.Client{
- Jar: cookieJar,
- }
- state.app = app.New()
- loginresult := widget.NewLabel("")
- usrf := widget.NewEntry()
- passf := widget.NewPasswordEntry()
- result := ""
- state.loginw = state.app.NewWindow("Loggboken")
- state.loginw.SetContent(widget.NewVBox(
- usrf,
- passf,
- layout.NewSpacer(),
- widget.NewButton("Logga in", func() {
- u := usrf.Text
- p := passf.Text
- state.login(u, p)
- }),
- widget.NewButton("Avsluta", func() { state.app.Quit() }),
- widget.NewLabel(result),
- loginresult,
- ))
- usrf.SetPlaceHolder("Användarnamn")
- state.loginw.Resize(fyne.Size{
- Width: 300,
- Height: 200,
- })
- state.loginw.CenterOnScreen()
- state.loginw.ShowAndRun()
- state.mainw.ShowAndRun()
- }
- func (s *State) login(u string, p string) {
- logind := "username=" + u + "&password=" + p
- fmt.Println(logind)
- body := POST(s.client, "", logind, "application/x-www-form-urlencoded")
- if body == "student" {
- s.loginw.Close()
- s.mainscreen()
- } else {
- fmt.Println("Fel vid inloggning!")
- return
- }
- }
- func (s *State) mainscreen() {
- fmt.Println("Mainscreen start!")
- s.mainw = s.app.NewWindow("Idag")
- s.mainw.SetContent(widget.NewVBox(
- widget.NewEntry(),
- widget.NewButton("SPARA", func() {}),
- widget.NewButton("Avsluta", func() { s.app.Quit() }),
- ))
- s.mainw.Resize(fyne.Size{
- Width: 500,
- Height: 200,
- })
- s.mainw.CenterOnScreen()
- fmt.Println("Mainscreen END!")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement