forked from gitea/gitea
1
0
Fork 0

display login error message when login post error

This commit is contained in:
FuXiaoHei 2014-03-03 20:35:44 +08:00
parent aad4856948
commit d8a24aff8c
2 changed files with 25 additions and 18 deletions

View File

@ -24,22 +24,26 @@ func Profile(r render.Render) {
} }
func SignIn(req *http.Request, r render.Render) { func SignIn(req *http.Request, r render.Render) {
if req.Method == "GET" { 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.HTML(200, "user/signin", map[string]interface{}{ r.HTML(200, "user/signin", map[string]interface{}{
"Title": "Log In", "Title": "Log In",
"Error": errString,
"Account": account,
}) })
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
}
r.Redirect("/")
} }
func SignUp(req *http.Request, r render.Render) { func SignUp(req *http.Request, r render.Render) {

View File

@ -2,17 +2,20 @@
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div class="container" id="gogs-body"> <div class="container" id="gogs-body">
<form action="/user/signin" method="post" class="form-horizontal gogs-card" id="gogs-login-card"> <form action="/user/signin" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
<h3>Log in</h3> <h3>Log in</h3>{{if .Error}}
<div class="form-group">
<div class="col-md-6 col-md-offset-3 alert alert-danger text-center"><strong>{{.Error}}</strong></div>
</div>{{end}}
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label">Username or Email: </label> <label class="col-md-4 control-label">Username or Email: </label>
<div class="col-md-6"> <div class="col-md-6">
<input name="account" class="form-control" placeholder="Type your username or e-mail address"> <input name="account" class="form-control" placeholder="Type your username or e-mail address" value="{{.Account}}" required="required">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label">Password: </label> <label class="col-md-4 control-label">Password: </label>
<div class="col-md-6"> <div class="col-md-6">
<input name="passwd" type="password" class="form-control" placeholder="Type your password"> <input name="passwd" type="password" class="form-control" placeholder="Type your password" required="required">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">