Beispiel #1
0
func LoginHandler(rw http.ResponseWriter, req *http.Request) {

	sess := GlobalSessions.SessionStart(rw, req)
	log.Println(&sess, sess.Get("account"))
	req.ParseForm()

	if req.Method == "GET" {
		t, err := template.ParseFiles("views/login.html")
		if err != nil {
			log.Println(err)
		}
		t.Execute(rw, sess.Get("account"))
	} else {

		name := req.FormValue("login")
		pwd := req.FormValue("password")
		log.Printf("name", name, pwd)
		account := service.Login(name, pwd)
		log.Printf("account", account.AccountName, account.Pwd)
		sess.Set("account", account)
		if account.Pwd == pwd {
			http.Redirect(rw, req, "/index", http.StatusFound)
		} else {

		}

	}

}
Beispiel #2
0
func LoginHandlerAPI(rw http.ResponseWriter, req *http.Request) {

	if req.Method == "POST" {
		req.ParseForm()
		name := req.FormValue("name")
		pwd := req.FormValue("password")
		log.Printf("name", name, pwd)
		account := service.Login(name, pwd)
		log.Printf("account", account.AccountName, account.Pwd)
		if account.Pwd == pwd {
			a, _ := json.Marshal(account)
			b := []byte(a)
			rw.Write(b)
		}
	}
}