aboutsummaryrefslogtreecommitdiff
path: root/routers/user/user.go
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@hexiaz.com>2014-03-03 20:35:44 +0800
committerFuXiaoHei <fuxiaohei@hexiaz.com>2014-03-03 20:35:44 +0800
commitd8a24aff8c2a293bd13f306625d3ba401f182f64 (patch)
tree66cee95b2da346f9c307797b942056099179791b /routers/user/user.go
parentaad4856948eeba50fdaedab34ca6346423aad158 (diff)
display login error message when login post error
Diffstat (limited to 'routers/user/user.go')
-rw-r--r--routers/user/user.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/routers/user/user.go b/routers/user/user.go
index cf131408..b7f9d148 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
- }
-
- // 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
+ 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)
}
- 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) {