From d8a24aff8c2a293bd13f306625d3ba401f182f64 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Mon, 3 Mar 2014 20:35:44 +0800 Subject: [PATCH] display login error message when login post error --- routers/user/user.go | 34 +++++++++++++++++++--------------- templates/user/signin.tmpl | 9 ++++++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/routers/user/user.go b/routers/user/user.go index cf1314086c4..b7f9d148d19 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -24,22 +24,26 @@ func Profile(r render.Render) { } func SignIn(req *http.Request, r render.Render) { - if req.Method == "GET" { - r.HTML(200, "user/signin", map[string]interface{}{ - "Title": "Log In", - }) - return + var ( + errString string + account string + ) + if req.Method == "POST" { + account = req.FormValue("account") + _, err := models.LoginUserPlain(account, req.FormValue("passwd")) + if err == nil { + // login success + r.Redirect("/") + return + } + // login fail + errString = fmt.Sprintf("%v", err) } - - // todo sign in - _, err := models.LoginUserPlain(req.FormValue("account"), req.FormValue("passwd")) - if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - }) - return - } - r.Redirect("/") + r.HTML(200, "user/signin", map[string]interface{}{ + "Title": "Log In", + "Error": errString, + "Account": account, + }) } func SignUp(req *http.Request, r render.Render) { diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 856e46d97b3..6527ae53f20 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -2,17 +2,20 @@ {{template "base/navbar" .}}
-

Log in

+

Log in

{{if .Error}} +
+
{{.Error}}
+
{{end}}
- +
- +