aboutsummaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-03 23:24:29 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-03 23:24:29 +0800
commitfea660f1d787f353f06632982861000c9078da2e (patch)
treebf34f22c98551e7b0c5dbc4bc58e6bc0a20efba2 /routers
parentb73cf0ee77cf035b118315568c605f4f54fa81aa (diff)
parent39ac95e5a2f256a840dac6206623100a7688ac16 (diff)
merged
Diffstat (limited to 'routers')
-rw-r--r--routers/user/user.go38
1 files changed, 21 insertions, 17 deletions
diff --git a/routers/user/user.go b/routers/user/user.go
index d2da19d5..5dc2c0b9 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -25,24 +25,28 @@ func Profile(r render.Render) {
}
func SignIn(req *http.Request, r render.Render, session sessions.Session) {
- if req.Method == "GET" {
- r.HTML(200, "user/signin", map[string]interface{}{
- "Title": "Log In",
- })
- return
- }
-
- // TODO: LDAP sign in
- user, 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")
+ user, err := models.LoginUserPlain(account, req.FormValue("passwd"))
+ if err == nil {
+ // login success
+ session.Set("userId", user.Id)
+ session.Set("userName", user.Name)
+ r.Redirect("/")
+ return
+ }
+ // login fail
+ errString = fmt.Sprintf("%v", err)
}
- session.Set("userId", user.Id)
- session.Set("userName", user.Name)
- 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) {