diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-06 11:42:14 -0500 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-06 11:42:14 -0500 |
commit | 56a7ab4da5d36e9311311c826c772bade7d031f0 (patch) | |
tree | fd329c1c5e31f7e40e4ac0c9893a9b370d4935d3 /routers | |
parent | d8b92b4bc99d642c7fd9a6080bdfa8d782e8c325 (diff) | |
download | gitea-56a7ab4da5d36e9311311c826c772bade7d031f0.tar.gz gitea-56a7ab4da5d36e9311311c826c772bade7d031f0.zip |
Finish log in user
Diffstat (limited to 'routers')
-rw-r--r-- | routers/user/user.go | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/routers/user/user.go b/routers/user/user.go index 0a85011a8b..2e6cb3d596 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -79,36 +79,45 @@ func SignedInUser(session sessions.Session) *models.User { return user } -func SignIn(req *http.Request, r render.Render, session sessions.Session) { +func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render.Render, session sessions.Session) { // if logged, do not show login page if IsSignedIn(session) { r.Redirect("/") return } - var ( - errString string - account string - ) - // if post, do login action - 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("/") + + data["Title"] = "Log In" + + if req.Method == "GET" { + r.HTML(200, "user/signin", data) + return + } + + if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { + r.HTML(200, "user/signin", data) + return + } + + user, err := models.LoginUserPlain(form.UserName, form.Password) + if err != nil { + if err.Error() == models.ErrUserNotExist.Error() { + data["HasError"] = true + data["ErrorMsg"] = "Username or password is not correct" + auth.AssignForm(form, data) + r.HTML(200, "user/signin", data) return } - // login fail - errString = fmt.Sprintf("%v", err) - } - // if get or error post, show login page - r.HTML(200, "user/signin", map[string]interface{}{ - "Title": "Log In", - "Error": errString, - "Account": account, - }) + + data["ErrorMsg"] = err + log.Error("user.SignIn: %v", data) + r.HTML(500, "base/error", nil) + return + } + + // login success + session.Set("userId", user.Id) + session.Set("userName", user.Name) + r.Redirect("/") } func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r render.Render) { |