display login error message when login post error

tokarchuk/v1.17
FuXiaoHei 11 years ago
parent aad4856948
commit d8a24aff8c
  1. 30
      routers/user/user.go
  2. 9
      templates/user/signin.tmpl

@ -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 (
r.HTML(200, "user/signin", map[string]interface{}{ errString string
"Title": "Log In", 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 return
} }
// login fail
// todo sign in errString = fmt.Sprintf("%v", err)
_, 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("/") r.HTML(200, "user/signin", map[string]interface{}{
"Title": "Log In",
"Error": errString,
"Account": account,
})
} }
func SignUp(req *http.Request, r render.Render) { func SignUp(req *http.Request, r render.Render) {

@ -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">

Loading…
Cancel
Save