diff --git a/conf/app.ini b/conf/app.ini index 7a8970cb4a..dcc58c37f3 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,4 +1,4 @@ -APP_NAME = Gogs - Go Git Service +APP_NAME = Gogs: Go Git Service RUN_USER = lunny [repository] diff --git a/gogs.go b/gogs.go index 51ef3cf19d..72a967f01c 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.0.0.0301" +const APP_VER = "0.0.0.0303" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/user.go b/models/user.go index 086b02c82f..820597380d 100644 --- a/models/user.go +++ b/models/user.go @@ -34,7 +34,7 @@ const ( type User struct { Id int64 LowerName string `xorm:"unique not null"` - Name string `xorm:"unique not null" valid:"Required"` + Name string `xorm:"unique not null" valid:"AlphaDash;MinSize(5);MaxSize(30)"` Email string `xorm:"unique not null" valid:"Email"` Passwd string `xorm:"not null" valid:"MinSize(8)"` LoginType int diff --git a/routers/user/user.go b/routers/user/user.go index 5dc2c0b97d..a66a7b5f94 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -14,6 +14,7 @@ import ( "github.com/gogits/validation" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/utils/auth" "github.com/gogits/gogs/utils/log" ) @@ -50,18 +51,19 @@ func SignIn(req *http.Request, r render.Render, session sessions.Session) { } func SignUp(req *http.Request, r render.Render) { + data := map[string]interface{}{"Title": "Sign Up"} if req.Method == "GET" { - r.HTML(200, "user/signup", map[string]interface{}{ - "Title": "Sign Up", - }) + r.HTML(200, "user/signup", data) return } + // Front-end should do double check of password. u := &models.User{ Name: req.FormValue("username"), Email: req.FormValue("email"), Passwd: req.FormValue("passwd"), } + valid := validation.Validation{} ok, err := valid.Valid(u) if err != nil { @@ -69,23 +71,21 @@ func SignUp(req *http.Request, r render.Render) { return } if !ok { - for _, err := range valid.Errors { - log.Warn("user.SignUp -> valid user: %v", err) - } + data["HasError"] = true + data["ErrorMsg"] = auth.GenerateErrorMsg(valid.Errors[0]) + r.HTML(200, "user/signup", data) return } - err = models.RegisterUser(u) - if err != nil { - if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - }) - return - } - } + // err = models.RegisterUser(u) + // if err != nil { + // r.HTML(200, "base/error", map[string]interface{}{ + // "Error": fmt.Sprintf("%v", err), + // }) + // return + // } - r.Redirect("/") + // r.Redirect("/") } func Delete(req *http.Request, r render.Render) { diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 4358bf02bf..0294ba49a5 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -16,7 +16,7 @@ - {{.Title}} | {{AppName}} + {{.Title}} - {{AppName}} \ No newline at end of file diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index c4bd3a7a51..00112c03d3 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -7,7 +7,7 @@ Help - + user-avatar diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 6527ae53f2..f80b3199a2 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -1,7 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}}
-
+

Log in

{{if .Error}}
{{.Error}}
@@ -26,7 +26,7 @@
diff --git a/templates/user/signup.tmpl b/templates/user/signup.tmpl index 48e50a0037..e8854e4aca 100644 --- a/templates/user/signup.tmpl +++ b/templates/user/signup.tmpl @@ -1,8 +1,11 @@ {{template "base/head" .}} {{template "base/navbar" .}}
- +

Sign Up

+ {{if .HasError}} +
{{.ErrorMsg}}
+ {{end}}
@@ -37,7 +40,7 @@ diff --git a/utils/auth/auth.go b/utils/auth/auth.go new file mode 100644 index 0000000000..1099103403 --- /dev/null +++ b/utils/auth/auth.go @@ -0,0 +1,15 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package auth + +import ( + "fmt" + + "github.com/gogits/validation" +) + +func GenerateErrorMsg(e *validation.ValidationError) string { + return fmt.Sprintf("%v", e.LimitValue) +} diff --git a/web.go b/web.go index 4fca90a298..ca3b4fcf1a 100644 --- a/web.go +++ b/web.go @@ -53,11 +53,9 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", routers.Dashboard) - m.Any("/login", user.SignIn) - m.Any("/user/signin", user.SignIn) + m.Any("/user/login", user.SignIn) - m.Any("/sign-up", user.SignUp) - m.Any("/user/signup", user.SignUp) + m.Any("/user/sign_up", user.SignUp) m.Get("/user/profile", user.Profile) // should be /username m.Any("/user/delete", user.Delete)