From c5132b87a604506e2af0ad0322c9ccd76fe05987 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 2 Mar 2014 22:25:13 +0800 Subject: [PATCH] finished signin and login --- routers/user/user.go | 21 ++++++++++++++++++--- templates/base/error.tmpl | 6 ++++++ templates/user/signin.tmpl | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 templates/base/error.tmpl diff --git a/routers/user/user.go b/routers/user/user.go index 7cd8bca5504..cf1314086c4 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -32,6 +32,14 @@ func SignIn(req *http.Request, r render.Render) { } // 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("/") } func SignUp(req *http.Request, r render.Render) { @@ -61,9 +69,16 @@ func SignUp(req *http.Request, r render.Render) { } err = models.RegisterUser(u) - r.HTML(403, "status/403", map[string]interface{}{ - "Title": fmt.Sprintf("%v", err), - }) + if err != nil { + if err != nil { + r.HTML(200, "base/error", map[string]interface{}{ + "Error": fmt.Sprintf("%v", err), + }) + return + } + } + + r.Redirect("/") } func Delete(req *http.Request, r render.Render) { diff --git a/templates/base/error.tmpl b/templates/base/error.tmpl new file mode 100644 index 00000000000..8d3c36be9a7 --- /dev/null +++ b/templates/base/error.tmpl @@ -0,0 +1,6 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ An error is occupied : {{.Error}} +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index dcdeaa77c57..c3a3131f5da 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}}
-
+

Log in